user3837816
user3837816

Reputation: 119

Fetch objectId from a User in parse

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)?

Upvotes: 1

Views: 1380

Answers (2)

Jack
Jack

Reputation: 324

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

Upvotes: 0

Automate This
Automate This

Reputation: 31364

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);
             }
         }
}

Upvotes: 1

Related Questions