I have Messages class table and inside the table contains "messageTextColumn" column and "user" column.
This "user" column, I created it with type pointer and the target class is _User which is parse main class.
I want to store both user's saved messages and the userId so that I can query it and show it in that user's message tableview cell which will show the list of every messages that the user had saved in my app.
This is my code:
@IBAction func addMessage(sender: AnyObject) {
var newMessage = addMessageText.text
let message = PFObject(className: "Messages")
var user = PFUser.currentUser()
message["messageTextColumn"] = newMessage
message["user"] = user
message.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
if (success) {
println("added to Message Class")
println(user)
message.saveInBackground()
} else {
// Error saving message
}
}
}
The problem is when I run this, the log shows:
[Error]: can't add a non-pointer to a relation (Code: 111, Version: 1.7.4)
and the message was not saved on Parse at all but when I deleted this line of code:
message["user"] = user
I was able to save the message to Parse Messages class table but not the userID of the user who saved it.