我想检索一组正在“搜索”的用户,然后从数组中随机选择一个并将其添加为“合作伙伴”。这是我所拥有的:
- (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:@"searching" notEqualTo:@0)。有谁知道如何解决这一问题?
谢谢!