Swift3 无法分配类型为';(UIViewController?,n错误?)->;无效';输入';((UIViewController?,错误?->;无效)';
我有这个功能来验证播放器,它在xcode8 beta 6之前运行良好:Swift3 无法分配类型为';(UIViewController?,n错误?)->;无效';输入';((UIViewController?,错误?->;无效)';,swift3,xcode8-beta6,Swift3,Xcode8 Beta6,我有这个功能来验证播放器,它在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 authen
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)
我不知道发生了什么。
有人能帮我吗?对不起,答案很简单,只要换一行就行了:
self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: NSError?) -> Void in
到
我的错!对不起 如果您不理解错误消息,我强烈建议您使用代码补全重新键入函数以获得正确的签名。我有它,我只是没有正确阅读错误消息,我认为它与此相关,并试图找出解决方法,当我看到答案显而易见时。
self.localPlayer.authenticateHandler = {(viewController: UIViewController?, error: Error?) -> Void in