1

i'm new to parse and i'm trying to fetch a user objectId, but whatever i cant seem to return the objectId. I can easily return the username. this is my query:

                 PFQuery *query = [PFUser query];
                 [query whereKey:@"username" equalTo:[[PFUser currentUser] objectForKey:@"username"]];
                 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                     if (!error) {
                         if (objects.count) {
                             NSLog(@"%@", [objects lastObject]);

                         }
                }
            }];

This returns something like this:

<PFUser:9dcc65tsdr:(null)> {
    username = AEleQFdBx9jdtypfsQmLtzAvW;
}

How do i return the objectId which is between PFUser and (null)?

2 Answers 2

1

You can use object.objectId like this:

PFQuery *query = [PFUser query];
 [query whereKey:@"username" equalTo:[[PFUser currentUser] objectForKey:@"username"]];
 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
     if (!error) {
         if (objects.count) {
             for (PFObject *object in objects){
                NSLog(@"Object ID: %@", object.objectId);
             }
         }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can also use this: [[PFUser currentUser]objectId] much faster and works much better because you don't have to run a whole PFQuery.

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.