如何查找查询中找到的对象数量?以下代码始终打印" 0",但在数据库中有一个用户具有该用户名。
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");
}
}];
我做错了什么?
答案 0 :(得分:1)
应使用_User
类的+query
方法对PFUser
类执行查询
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");
}
}];
答案 1 :(得分:0)
试试这个,因为解析默认用户实体是以“_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");
}
}];