Reputation: 311
How do I find the number of objects found in a query? The following code is always printing "0", but there is a user with that username in the database.
PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query whereKey:@"username" equalTo:self.usernameField.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if ([objects count] == 0) {
NSLog(@"error %lu", (unsigned long)[objects count]);
}
else {
NSLog(@"no error");
}
}];
What am I doing wrong?
Upvotes: 0
Views: 77
Reputation: 6038
Performing a query on the _User
class should be done using the +query
method of the PFUser
class
PFQuery *userQuery = [PFUser query]; //Note the difference here.
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if ([objects count] == 0) {
NSLog(@"error %lu", (unsigned long)[objects count]);
}
else {
NSLog(@"no error");
}
}];
Upvotes: 1
Reputation: 998
Try This , Because parse default user entity is initiated with "_User"
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"username" equalTo:self.usernameField.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if ([objects count] == 0) {
NSLog(@"error %lu", (unsigned long)[objects count]);
}
else {
NSLog(@"no error");
}
}];
Upvotes: 0