swiftyboi
swiftyboi

Reputation: 3221

How can I update a field in the PFUser.currentUser() object?

I feel very stupid for asking this, but for the life of me, I am unable to figure this out. I just need to take the value of my "wants" field and add 1 to it.

My code is here:

var user = PFUser.currentUser()
let number = user["wants"]
user["wants"] = number + 1
user.save()

Please help me! I'm sure this is probably a very simple process and I'm probably overthinking it!

Upvotes: 1

Views: 424

Answers (1)

Rajeev Bhatia
Rajeev Bhatia

Reputation: 2994

If this is a counter, you could update it using

PFUser.currentUser().incrementKey("Wants")

and then save the object

more info at the official parse documentation

Parse User docs

Upvotes: 1

Related Questions