0

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)
            }
        }
    }

}

2 Answers 2

1

As you are using addUniqueObject:forKey: to add to the array you can use removeObject:forKey: to remove from the array and then save.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

How would I do go about doing that exactly?
Oh wait I figured it out! Thanks for helping me! (:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.