2

I use the signing up feature of Parse.com just as describe here. Here's my code:

 user.signUpInBackgroundWithBlock {
    (succeeded: Bool!, error: NSError!) -> Void in
    if error == nil {
      // Hooray! Let them use the app now.
    } else {
      let errorString = error.userInfo["error"] as NSString
      // Show the errorString somewhere and let the user try again.
    }
  }
}

Unfortunately, I've updated my project from swift 1.1 to swift 1.2 and get the following compiler error:

Function signature '(Bool!, NSError!)->void is not compatible with excepted type '@objc_block (Bool,NSError!)->Void'

it's on the following line:

user.signUpInBackgroundWithBlock {
        (succeeded: Bool!, error: NSError!) -> Void in

Does anybody know how can I fox that ? Thanks !

2 Answers 2

7

Your succeeded variable is a 'Bool!' but what the block returns is a 'Bool' (without exclamation mark).

The solution would be:

user.signUpInBackgroundWithBlock {
    (succeeded: Bool, error: NSError!) -> Void in
    if error == nil {
      // Hooray! Let them use the app now.
    } else {
      let errorString = error.userInfo["error"] as NSString
      // Show the errorString somewhere and let the user try again.
    }
  }
}

Too see more about optionals go to the apple doc

Sign up to request clarification or add additional context in comments.

Comments

2

I had the same problem with save in background with block. It looks like parse returns a "Bool not a Bool!"...however error is an NSError? unless you "!" it.

something.saveInBackgroundWithBlock {
            (succeeded: Bool, error: NSError?) -> Void in

code
}

1 Comment

Have you tried: something.saveInBackgroundWithBlock { (succeeded: Bool, error: NSError!) -> Void in indeed ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.