Reputation: 119
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
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
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