On my app there is an option to like posts. I use this function which I assigned to the like button with .addTarget to add the user's objectId to an array which is counted to establish how many likes there are. I want to know how I can remove a name from the array, like if someone wants to unlike the post.
func like(sender: AnyObject) {
var buttonPosition: CGPoint = sender.convertPoint(CGPointZero, toView: self.table)
var indexPath: NSIndexPath = self.table.indexPathForRowAtPoint(buttonPosition)!
var postsQuery = PFQuery(className: "Post")
postsQuery.whereKey("message", equalTo: messages[indexPath.row])
postsQuery.findObjectsInBackgroundWithBlock { (posts, error) -> Void in
if let posts = posts {
for post in posts {
post.addUniqueObject(PFUser.currentUser()!.objectId!, forKey: "likers")
println(self.likesArray)
post.saveInBackground()
self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
}
}
}