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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With