【问题标题】:Cannot assign value of type '(UIViewController?, NSError?) -> Void' to type '((UIViewController?, Error?) -> Void)?'无法将类型“(UIViewController?,NSError?)-> Void”的值分配给类型“((UIViewController?,错误?)-> Void)?”
【发布时间】:2016-08-18 10:27:11
【问题描述】:

我有这个功能来验证播放器,它工作得很好,直到 xcode8 beta 6:

 func authenticateLocalPlayer()
{
    print(#function)
    // WillSignIn
    self.delegate?.willSignIn?()

    // The player authenticates in an asynchronous way, so we need a notification to inform when the authentication was completed successfully
    // If the local player is already connected, return and notificate
    if GameKitHelper.sharedGameKitHelper.localPlayer.isAuthenticated {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: Constants.LocalPlayerIsAuthenticated), object: nil)
        return
    }

    // Calling the authentication view controller
    self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: NSError?) -> Void in

        self.addLastError(error: error)

        if (viewController != nil)
        {
            self.addAuthenticationViewController(authenticationViewController: viewController!)
        }

            // If the localPlayer authenticated successfully notificate
        else if (self.localPlayer.isAuthenticated == true)
        {
            self.gameCenterConnected = true
            print("Local player ID: \(self.localPlayer.playerID)")
            print("Local player Alias: \(self.localPlayer.alias)")
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: Constants.LocalPlayerIsAuthenticated), object: nil)

        }
            // If the localPlayer failed to authenticate
        else
        {
            self.gameCenterConnected = false
        }

        if (error != nil)
        {
            //  Handle error here
        }
    }
}

现在我收到此错误“无法将类型 '(UIViewController?, NSError?) -> Void' 的值分配给类型 '((UIViewController?, Error?) -> Void)?” " 在这一行

 self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: NSError?) -> Void in

        self.addLastError(error: error)

        if (viewController != nil)

我不知道发生了什么。 谁能帮帮我?

【问题讨论】:

  • 如果您不理解错误消息,我强烈建议您使用代码完成重新键入函数以获得正确的签名。
  • 我知道了,我只是没有正确阅读错误消息,我认为它与此github.com/apple/swift-evolution/blob/master/proposals/… 有关,并在看到答案时试图弄清楚如何解决它很明显。

标签: swift3 xcode8-beta6


【解决方案1】:

对不起,答案很简单,只需要更改这一行:

self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: NSError?) -> Void in

self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: Error?) -> Void in

我的错!对不起!

【讨论】:

    猜你喜欢
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    相关资源
    最近更新 更多