1

i have this function to authenticate the player and it worked just fine until 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
        }
    }
}

now i get this error "Cannot assign value of type '(UIViewController?, NSError?) -> Void' to type '((UIViewController?, Error?) -> Void)?' " in this line

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

        self.addLastError(error: error)

        if (viewController != nil)

and i have no idea what is going on. can anyone help me please?

i6x86
  • 1,557
  • 6
  • 23
  • 42
  • If you don't understand the error message I strongly recommend to retype the function using code completion to get the proper signature. – vadian Aug 18 '16 at 14:27
  • i have it, i just didn't read properly the error message, and i thought that it was related to this https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md and tried to figure out how to resolve it when i saw that the answer was obvious. – i6x86 Aug 18 '16 at 14:32

1 Answers1

2

sorry, the answer was as simple as only had to change this line:

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

to

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

my bad! sorry!

i6x86
  • 1,557
  • 6
  • 23
  • 42