I got this error message when trying to search object UserDetail.
Error message
/Users/MNurdin/Documents/iOS/xxxxx/ViewController.swift:125:15: Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type '(PFUser?, (PFObject?, NSError?) -> Void)'
My code
var user = PFUser.currentUser()
var query = PFQuery(className:"UserDetail")
query.getObjectInBackgroundWithId(user) { //error message here
(gameScore: PFObject?, error: NSError?) -> Void in
if error != nil {
println(error)
} else if let gameScore = gameScore {
gameScore["cheatMode"] = true
gameScore["score"] = 1338
gameScore.saveInBackground()
}
}
You are using the wrong parameter types in the block passed to PFQuery
's getObjectInBackground(_:block:)
method. According to the docs, the block
argument takes an NSArray
(this can be bridged to a Swift array of AnyObject
), and an error:
query.getObjectInBackgroundWithId(user?.objectId) { (object: [AnyObject]?, error: NSError?) -> Void in
// ...
}
In addition, the objectId
parameter should be a string, but you appear to be passing in a PFUser
instance.