Reputation: 1609
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)
}
}
}
}
Upvotes: 0
Views: 56
Reputation: 119041
As you are using addUniqueObject:forKey:
to add to the array you can use removeObject:forKey:
to remove from the array and then save.
Upvotes: 1
Reputation: 1252
Parse array is really just a JSON dictionary. One way of reordering data is to put an parse array into dictionary , create new dictionary without data that needs to be deleted , and then save new array into parse array.
Upvotes: 1