0

in my app there is a function that is analogous to liking a post. In my parse database, I have a "Like" class. In the Like class are 2 columns, one "from_user" that is a pointer column pointing to the user who liked it. The other is "to_post", pointing to the post that was liked. my code is:

    var likeObject = PFObject(className: "Like")
    likeObject["from_user"] = PFUser.currentUser()
    likeObject["to_post"] = objectIDArray[0]

    likeObject.saveInBackground()

For reference, the objectIDArray is an array that contains 1 element, the object ID of the given post that I want to like.

But when I try this, I get an error saying "expected type *Post, got String" which refers to the line of code:

       likeObject["to_post"] = objectIDArray[0]

So how do I make it so that the object ID of the post (that I do have access to) can be used to point to that specific post?

thanks

1 Answer 1

0

What you want to do is use a pointer to the Post class. The parameter you pass to the to_post key should be of type PFObject*, but instead you're passing a NSString* (the object id).

Considering you already have the ObjectID of the post, what you have to do is fetch the PFObject from that id and set it to your likeObject.

Try this:

var query = PFQuery(className:"Post")
query.getObjectInBackgroundWithId(objectIDArray[0]) {
  (post: PFObject?, error: NSError?) -> Void in
  if error == nil && post != nil {
    likeObject["to_post"] = post
  } else {
    println(error)
  }
}
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.