swiftparse-platformpfquerypfobjectpfuser

Retrieve user's data with only the user's objectId - Parse & Swift


I am a beginner with swift and parse, but I am to make an App in which I have to retrieve a user's First Name and post it in a tableView. The thing is that I can't find a way to retrieve the user's First Name with only the user's objectId. I found this on the website during my research but it does not seemed to be what I want to do. I have also tried to do :

userNameLabel.text = (interest.user!["FirstName"] as! String)

I get the error : 'NSInternalInconsistencyException', reason: 'Key "FirstName" has no data. Call fetchIfNeeded before getting its value.'

I guess the problem is because it thinks it is a PFObject and therefore does not see it as a String (??)

Anyway does someone have an idea on how I can retrieve my user ("interest.user") First Name ?

Thank you for your time.


Solution

  • Since your user object is a pointer, when you run your query you need to tell Parse to include any extra information that's not part of that class. In this case, since it's a pointer, you need to do query.includeKey("user") or whatever the name of the column is that points to your user class.