SWIFT + Parse signUpInBackgroundWithBlock no longer works: Xcode 6.3.1 [duplicate]

血红的双手。 提交于 2020-01-05 07:59:11

问题


I'm using the latest parse code from the parse.com for user.signupInBackgroundWithBlock

user.signUpInBackgroundWithBlock {
            (succeeded: Bool?, error: NSError?) -> Void in
            if let error = error {
                let errorString = error.userInfo?["error"] as? NSString
               self.showAlertWithText(message: "\(error)")
            } else {
                self.performSegueWithIdentifier("createNewUserAndGoToDashboard", sender: self)
            }

I just upgraded to x-code 6.3.1 and it no longer works. This is copied directly from Parse.com, but I'm getting an error on the user.signUp line:

1.0/SIgnUpViewController.swift:48:46: Function signature '(Bool?, NSError?) -> Void' is not compatible with expected type

'@objc_block (Bool, NSError!) -> Void'

any tips?


回答1:


have you tried it without the "?" after the Bool

user.signUpInBackgroundWithBlock {
            (succeeded: Bool, error: NSError?) -> Void in
            if let error = error {
                let errorString = error.userInfo?["error"] as? NSString
                self.showAlertWithText(message: "\(error)")
            } else {
                self.performSegueWithIdentifier("createNewUserAndGoToDashboard", sender: self) }



回答2:


Try this.

user.signUpInBackgroundWithBlock { (returnedResult, returnedError) -> Void in
        if returnedError == nil
        {
            self.dismissViewControllerAnimated(true, completion: nil)
        }
        else
        {
            self.showAlert("There was an error with your sign up", error: returnedError!)
        }
    }


来源:https://stackoverflow.com/questions/29892933/swift-parse-signupinbackgroundwithblock-no-longer-works-xcode-6-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!