Andrea Gottardo Andrea Gottardo - 5 months ago 27
Objective-C Question - Getting pointer data contained in [PFUser currentUser]

I am using the iOS SDK, and I don't know what method I need to call to make sure that the PFUser currentUser contains the data for each pointer contained in it. It is probably very simple, but, as a beginner with this platform, I cannot find a solution.

Just to clarify, I am trying to get the username item in the following. It looks like it is always null, even though I am calling

[[PFUser currentUser] fetchIfNeeded]
before proceeding:

[[[PFUser currentUser] objectForKey:@"partner"] objectForKey:@"username"];

Thank you,



You can do it in a single query by using includeKey:

PFQuery *query = [PFUser query];
[query includeKey:@"partner"];
[query includeKey:@"anotherPointerColumnName"];
[query getObjectInBackgroundWithId:[[PFUser currentUser] objectId]
                             block:^(PFObject *populatedUser, NSError *error) {
    PFObject *partner = populatedUser[@"partner"];
    PFObject *another = populatedUser[@"anotherPointerColumnName"];

You can also use deeper levels, so if partner contained a pointer in it you needed called deeperPointerColumnName:

[query includeKey:@"partner.deeperPointerColumnName"];

Then in your completion block you can read it after you get the partner:

PFObject *partner = populatedUser[@"partner"];
PFObject *deeper = partner[@"deeperPointerColumnName"];