0
votes

New to Parse backend and coding all together.

Looking to create a "Favorite" function in my app so that users can save products that they like for later by tapping a simply UIButton.

I'm simply trying to figure out how to save the toUser (user whose product post is being favorited) and the fromUser (user who is doing the favoriting) in Parse.

Here is my code:

@IBAction func tagProductButton(sender: AnyObject) {

        var favoritePost = PFObject(className: "Tag")
        favoritePost["tagger"] = PFUser.currentUser()
        favoritePost["productId"] = ??
        favoritePost["userTagged"] = ??

        favoritePost.saveInBackground()

    }

"tagger" = toUser "userTagged" = fromUser

Thank you in advance! remember, I've only been coding for about a month now

1

1 Answers

0
votes

You should set the columns product and userTagged (from the Tag table) as Pointers if they are not already. Don't just use the ID as a String. You will need a reference to the Product (parse object) being tagged, so your code could look something like:

    favoritePost["product"] = product
    favoritePost["userTagged"] = product["user"]

You may not really need the userTagged field on the Tag table, since the user tagged is probably already attached to the product, but this may may other searches easier.