Reputation: 2237
I'm trying to increment a number in my parse table under the column "votes". Here's my code:
func upVote() {
var reviewQuery: PFQuery = PFQuery(className: "reviews")
reviewQuery.whereKey("content", equalTo: reviewTextView.text)
reviewQuery.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
println(object)
let review:PFObject = object as! PFObject
review.incrementKey("votes", byAmount: 1)
}
}
}
}
When I print the object in the console I can see that it is the correct object that I'm looking for. It looks like this:
<reviews:ZqgSVL1Tsd:(null)> {
content = "njk\n";
reviewer = "<PFUser:6387CJtYI1>";
votes = 1;}
But when I look at my parse end, the number of votes has not changed. What am I doing wrong?
Upvotes: 0
Views: 400
Reputation: 1498
After you modify an object, however small the modification, you must save it after. You are not saving your changes to the object review
.
You have several options for saving, including save()
, saveInBackground()
, saveEventually()
, and more. See the documentation for PFObject for more information:
https://www.parse.com/docs/ios/api/Classes/PFObject.html#//api/name/save
For example, you could save the object synchronously with
review.save()
and you could save the object asynchronously with review.saveInBackground()
.
Upvotes: 1
Reputation: 4176
Save the object with
review.saveInBackground()
after incrementing the key.
Upvotes: 2