我想检索一组用户"搜索"然后从数组中随机选择一个并将其添加为"合作伙伴"。这就是我所拥有的:
- (IBAction)searchForPlayer:(id)sender {
[self.currentUser setObject:@1 forKey:@"searching"];
[self.currentUser saveInBackground];
PFQuery *findPotential = [PFQuery queryWithClassName:@"User"];
[findPotential whereKey:@"searching" notEqualTo:@0];
[findPotential findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"Potential players: %i",objects.count);
if(error){
NSLog(@"Error!");
}
else {
if (objects.count == 0) {
NSLog(@"None found");
}
else {
int partnerNum = arc4random_uniform(objects.count)+1;
PFUser *newPartner = [objects objectAtIndex:partnerNum];
PFRelation *partners = [self.currentUser relationForKey:@"partners"];
[partners addObject:newPartner];
}
}
}];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(error){
NSLog(@"Error!");
}
}];
}
由于某种原因,没有找到具有指定约束的对象(whereKey:@"搜索" notEqualTo:@ 0)。有谁知道如何解决这一问题?
谢谢!
答案 0 :(得分:0)
立即错误在您的查询声明中。用户类不是由字符串"用户",它实际上" _Users"表示。但是,您应该使用以下命令创建用户查询:
PFQuery *findPotential = [PFUser query];