问题
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