Objective c 解析数组中的查找字符串

Objective c 解析数组中的查找字符串,objective-c,arrays,parse-platform,pfquery,Objective C,Arrays,Parse Platform,Pfquery,我正在使用parse并尝试使用下面的代码来检查哪些用户在数组@“Id1”中有特定的字符串。但是我没有拿回任何东西。whereKey:containsString是否仅用于搜索解析字符串值?如果是,如何搜索解析数组以查看它们是否包含字符串?提前谢谢 NSString *searchId = [[NSUserDefaults standardUserDefaults] objectForKey:@"searchId"]; PFQuery *query = [PFUser query]; //1

我正在使用parse并尝试使用下面的代码来检查哪些用户在数组@“Id1”中有特定的字符串。但是我没有拿回任何东西。whereKey:containsString是否仅用于搜索解析字符串值?如果是,如何搜索解析数组以查看它们是否包含字符串?提前谢谢

NSString *searchId = [[NSUserDefaults standardUserDefaults] objectForKey:@"searchId"];

PFQuery *query = [PFUser query]; //1

 [query whereKey:@"Id1" containsString:searchId];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {//4
    if (!error) {
        NSLog(@"1");
        self.ObjectsArray = nil;
        self.ObjectsArray = [[NSArray alloc] initWithArray:objects];
    } else {
        [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Please make sure you have a proper device connection." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    }
}];

如果您正在寻找完整的字符串,则更容易。要在数组中查找单个值,只需使用
whereKey:equalTo:
,如下所述:

这将返回数组中至少有一个条目等于搜索条件的行(处理数字、字符串、布尔值等)

相反,如果您真的想查找数组中至少有一个项包含字符串的记录,那么您将不得不采取一些技巧

一种选择是有一个不可见的字段,称为(例如)“Id1_搜索”。创建更新前云代码处理程序,将所有数组值合并到逗号列表中,并转换为小写。然后可以在该新字段上使用
whereKey:containssString:

[query whereKey:@"Id1" equalTo:searchId];