So I've set up my relations correctly in Parse using the following code:
var user = PFUser.currentUser()
var relation = user.relationForKey("likes")
relation.addObject(self.post)
user.saveInBackgroundWithBlock({ (Bool, error) -> Void in
println("user likes this post")
// Used for tracking in the PFTableCell for UI parts
self.userLikes = true
})
When the view loads, I need to change the buttons to Liked and the colour etc. I'd like to get all the users who liked this particular post but cannot figure out the query? It will give me some other useful info (e.g. I could display usernames of people who liked the post).
As a workaround I can get all the posts the user likes by doing:
var user = PFUser.currentUser()
var relation = user.relationForKey("likes")
relation.query().findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error != nil {
// There was an error
println(error)
} else {
// objects has all the Posts the current user liked and do something.
println(objects)
}
}
But that's not what I'm after? I'm using Swift and the Parse SDK, but will happily have the answer in Obj C and I'll translate. The Parse docs suggestion is wrong: https://www.parse.com/docs/ios_guide#objects-pointers/iOS I could store the like against the post rather than the user, but that would mean I'd have to open up access rights to the post which is a no-no