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]()
I can then use the indexPath of a cell to get the relevant information from the arrays above.
Each cell also has a UIButton (for casting a vote as well as other information).
To get the indexPath
of which cell has been clicked I use:
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?
From this point I'm a little unsure of the most efficient way of updating my Parse table's score attribute.
After looking at the Parse docs, I could potentially use a counter variable to save a score or an array.
Though, I think if that there could be syncronization issues in using a counter in the case that multiple users are trying to access the data at any one given time. (Unsure)
Is it possible that someone could share their way of doing such a task possibly so that the data from Parse can only be accessed by 1 user at any 1 given time to avoid such issues.