7
votes

I've checked the syntax a gazillion times here, on GitHub, parse.com & elsewhere, without any luck. The problem is when I'm calling saveInBackgroundWithBlock for PFObject I get the the following error:

Cannot invoke 'saveInBackgroundWithBlock' with an argument list of type '((Bool, NSError) -> Void)'

I'm on Xcode 6.3 beta 2. All frameworks are loaded to the project (including Bolts & Parse, but not provided by parse.com ParseCrashReporting & ParseUI), <Parse/Parse.h> & even <Bolts/Bolts.h> are brought through the Bridge Header.

var score = PFObject(className: "score")
    score.setObject("Rob", forKey: "name")
    score.setObject(95, forKey: "scoreNumber")
    score.saveInBackgroundWithBlock {
        (success: Bool!, error: NSError) -> Void in
        if success == true {
            println("Score created with ID: \(score.objectId)")
        } else {
            println(error)
        }
    }

Any thoughts?

3

3 Answers

9
votes

The error parameter is supposed to be an implicitly unwrapped optional, but not the success one:

(success: Bool, error: NSError!) -> Void in
              ^               ^

However unless you need to specify the type for whatever reason, I suggest you to use the closure simply as:

(success, error) in

less prone to type declaration errors.

7
votes

In Swift 1.2 the declaration of .saveInBackgroundWithBlock should look like this:

Void saveInBackgroundWithBlock(block: PFBooleanResultBlock?(Bool, NSError?) -> Void)

So it should have been as follows:

score.saveInBackgroundWithBlock {
        (success: Bool, error: NSError?) -> Void in
1
votes

The method wants the success and error variables set like this with the ! on the error:

(success: Bool, error: NSError!)
              ^               ^

But you've set the ! to the wrong variable:

(success: Bool!, error: NSError) 

As you see here:

enter image description here