Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com - Getting pointer data contained in [PFUser currentUser]

I am using the Parse.com 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,

Andrea

like image 573
Andrea Gottardo Avatar asked Aug 18 '26 22:08

Andrea Gottardo


1 Answers

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"];
like image 151
Timothy Walters Avatar answered Aug 21 '26 15:08

Timothy Walters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!