0

我想检索一组正在“搜索”的用户,然后从数组中随机选择一个并将其添加为“合作伙伴”。这是我所拥有的:

- (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)。有谁知道如何解决这一问题?

谢谢!

4

1 回答 1

0

直接错误在您的查询声明中。用户类不是由字符串“Users”表示的,它实际上是“_Users”。但是,您应该使用以下命令创建用户查询:

PFQuery *findPotential = [PFUser query];
于 2014-07-08T20:28:10.067 回答