in my app Im trying to give the user points every time they create an event. I am setting up a PFQuery to retrieve the current score then saving the required points back to the class. My problem is that I can't update the score once it has been created so I need a way to "Update" the current score data with the added score.
This is my code:
// Give the User Points
let saveScore = PFUser.currentUser()
var query = PFQuery(className:"User")
query.whereKey("score", equalTo: saveScore!)
query.findObjectsInBackgroundWithBlock ({
objects, error in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
let Score = object["score"] as! String
println(object.objectId)
let Points = ("100" + Score)
saveScore!.setObject(Points, forKey: "score")
saveScore!.saveInBackgroundWithBlock { (success: Bool,error: NSError?) -> Void in
println("Score added to User.");
}
}
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
})
Can anyone help? Thanks