【问题标题】:ParseSwift.initialize shows Cannot convert value of type errorParseSwift.initialize 显示无法转换类型错误的值
【发布时间】:2021-07-18 19:46:02
【问题描述】:

我认为是时候开始使用 Swift 了,所以我正在对一个 obj C 应用程序进行完全重写。这个应用程序使用 Parse Server 和 CocoaPods。在我的 AppDelegate.swift 中的 ParseSwift 文档示例之后,我添加了

import ParseSwift

class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        ParseSwift.initialize(applicationId: "AppID", clientKey: "", serverURL: URL(string: "https://server")!, liveQueryServerURL: URL(string: "https://server")!, authentication: ((URLAuthenticationChallenge,(URLSession.AuthChallengeDisposition,URLCredential?) -> Void) -> Void))

等等...但是初始化行显示错误

无法将类型 '((URLAuthenticationChallenge, (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void).Type' 的值转换为预期的参数类型 '((URLAuthenticationChallenge, (URLSession.AuthChallengeDisposition, URLCredential?) - > 无效)-> 无效)?'

【问题讨论】:

  • 你不能那样初始化它...URLAuthenticationChallengeURLSession.AuthChallengeDispositionURLCredential?只是一个类型。您需要一个实际的实例化对象

标签: swift parse-platform


【解决方案1】:

身份验证是一个可选字段,因此您无需传递值。

如果您没有对身份验证做任何事情(大多数情况下),您不应该通过任何事情:

ParseSwift.initialize(applicationId: "AppID",
                     clientKey: "",
                     serverURL: URL(string: "https://server")!)

当您计划将身份验证用于证书固定时,应将其用作尾随闭包:

ParseSwift.initialize(applicationId: "AppID",
                     clientKey: "",
                     serverURL: URL(string: "https://server")!) { (challenge, credential) in
            credential(.performDefaultHandling, nil)
        }

【讨论】:

    猜你喜欢
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    相关资源
    最近更新 更多