2013-06-12 122 views
0
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]; 

我正在为一个数组中的多个userIds设置这个复合谓词,我需要使用OR从这些用户id获取用户。复合谓词不工作

以上不工作,但是当我使用

NSPredicate *predicate1=[NSPredicate predicateWithFormat:@"(userID like[cd] %@) 
          OR (userID like[cd] %@)",@"sheetal2", @"sheetal3"]; 
[arrayOfPredicates addObject:predicate1]; 

现在,这是working..Can anyboady告诉硬编码什么我的代码问题..

感谢

+0

这可能听起来很傻,您正在使用用户ID的第一个和其他的你正在起诉EVENTID? – Anupdas

+0

@Anupdas离开的ID ...什么我是个说的是它不工作...我只是复制pasted..i已经Editted – sheetal

+1

当你发布的问题,没有留下任何余地猜测。即使现在你的上面的查询是区分大小写的,第二个是不区分大小写的?并且还会登录'arrayOfPredicates'来查看他们的内容。 – Anupdas

回答

1

在谓词使用的第一个代码==。在第二个代码中谓词使用LIKE[cd]。因为userIDNSString,所以使用LIKE通常是告诉谓词比较值的更好方式,但真正的区别在于第二种方法是区分大小写和区分变音不敏感,第一种方法需要精确匹配。

+0

你可以查看MartinR的评论[答](http://stackoverflow.com/a/16358617/767730)。我认为使用'LIKE'并不总是最好的。 – Anupdas

+2

谢谢@Anupdas,我已经改进了答案,并且我从来没有想过要做'== [cd]'之前的好信息。 – Wain

+0

@Wain遐我得到的答案...谢谢 – sheetal