Unable to call "saveInBackgroundWithBlock"

I checked the syntax gazillion times here on GitHub, parse.com and elsewhere, with no luck. The problem is that when I call saveInBackgroundWithBlock for PFObject, I get the following error:

Cannot call 'saveInBackgroundWithBlock' using argument list of type '((Bool, NSError) -> Void)'

I am on Xcode 6.3 beta 2. All frameworks are loaded into the project (including Bolts and Parse, but not provided by parse.com ParseCrashReporting and ParseUI), <Parse/Parse.h> and even <Bolts/Bolts.h> displayed through the Header bridge .

 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?

+7
ios swift
source share
3 answers

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

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

Thus, it should have been as follows:

 score.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in 
+7
source share

The error parameter must be implicitly expanded optional, but not success alone:

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

However, if you do not need to specify the type for any reason, I suggest you use closure just like:

 (success, error) in 

less prone to type declaration errors.

+9
source share

The method wants success and error variables to be set with ! on error :

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

But you installed ! to the wrong variable:

 (success: Bool!, error: NSError) 

As you can see here:

enter image description here

+1
source share

All Articles