I'm currently in the process of learning both Swift and Parse and for the question I'm asking I'm going to use a simple up vote on a cell.
So I've got a table view controller which is populated by a query to a table on Parse. To do this I create a query on the relevant table and then store the bits of information into arrays e.g. an array for usernames, and text posts and object ID's:
var postGrabber: [PFObject] = [PFObject]()
var pSenderUsername: [String] = [String]()
var pPostBody: [String] = [String]()
var objectId: [String] = [String]()
let btnPos: CGPoint = sender.convert(CGPoint.zero, to: self.tableView)
let indexPath = self.tableView.indexPathForRow(at: btnPos)!
let rowToAction = indexPath.first!
As a side note, objectAtIndexPath(rowToAction) does not seem to work in Swift 3, does anyone know of an alternative?
So you want to increment the
You can use
[post incrementKey:@"numberOfUpVotes"]; [post saveInBackground];
This will update the votes asynchronously, and the
incrementKey method is atomic. Let's say we have 5 users clicking on the "up" button at the same time, the value for key "numberOfUpVotes" will be 5 in stead of 1.
Also, you can specify your increment about by :
[post incrementKey:@"numberOfUpVotes" byAmount:[NSNumber numberWithInt:2]]
But I don't think this is gonna happen in your use case :)
You can read this post from Parse:
or you can see my question:
note: my code is in Objective-C, but it's pretty easy to convert that into Swift.