2

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

2 Answers 2

10

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"];
Sign up to request clarification or add additional context in comments.

3 Comments

yes, includeKey: is the one, this make the query include child PFObjects that have a reference stored at the provided key
what if the it's not partner but partners (array of pointers)?
The other issue with this is, it does not persist in PFUser.currentUser().
0

Well, I found a workaround by myself. It looks like the solution is to call the fetch method on the pointer before proceeding:

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

If there is a cleaner and swifter way of doing it (automatically for instance) I would really appreciate any advice.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.