复合谓词不起作用

时间:2013-06-12 05:57:29

标签: iphone ios objective-c nspredicate

NSMutableArray *arrayOfPredicates=[[NSMutableArray alloc]init];
[self.attendeeListSet enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
    NSString *userId=[obj userId];
    [arrayOfPredicates addObject:[NSPredicate predicateWithFormat:@"userID == %@",userId]];
}];
NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:arrayOfPredicates];
[request setPredicate:compoundPredicate];

我正在为数组中的多个userId设置此复合谓词,我需要使用OR从这些用户ID中获取用户。

以上不起作用,但当我使用

进行硬编码时
 NSPredicate *predicate1=[NSPredicate predicateWithFormat:@"(userID like[cd] %@) 
                            OR (userID like[cd] %@)",@"sheetal2", @"sheetal3"];  
[arrayOfPredicates addObject:predicate1];

现在这个工作正常。可以随便告诉我的代码有什么问题..

由于

1 个答案:

答案 0 :(得分:1)

在您的第一个代码中,谓词使用==。在第二个代码中,谓词使用LIKE[cd]。由于userIDNSString,因此使用LIKE通常是告诉谓词比较值的更好方法,但真正的区别在于第二种方法是大小写和变音符号不敏感的第一种方法需要完全匹配。

相关问题