I have a UITableView that is populated with games that a user is currently playing. I have a Pointer column in the Game table called Turn that points to a PFUser in the User table. Instead of setting the cell text to the objectID of the Turn value, I'd like to instead set it to the player's first name, which is stored in the User table.
The problem is that when I println the Turn pointer object, it only contains the objectID and I can't pull the first_name. Here's my code:
let object = gameResults[indexPath.row]
let user = object["turn"] as! PFUser
let userString = "\(object.first_name)"
cell.textLabel?.text = userString
return cell
The cell text just reads "nil". How do I get the user data from the User table that relates to the Turn pointer column?
The pointer column data are not included by default when using PFQuery.
Do this to tell your query to include the pointer data:
yourQuery.includeKey("turn")
This will get the user data from the user table and include it in the PFObject obtained.
UPDATE:
To get the first_name
field (or any field for that matter), the syntax is:
let userSting = user["first_name"] as String
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.