我正在使用NSPredicate进行过滤,
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@ )OR (UserName CONTAINS %@ ) ", myText,myText,myText];
NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate];
它工作正常,但它区分大小写。我需要过滤应该不区分大小写。
我试过了,
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY firstName CONTAINS %@ ) OR (ANY lastName CONTAINS %@ )OR (ANY UserName CONTAINS %@ ) ", myText,myText,myText];
但它会抛出错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.'
我无法理解this answer中提到的内容。任何人都可以建议我在上面的过滤中应该改变什么?
答案 0 :(得分:16)
将所有CONTAINS
替换为CONTAINS[c]
。方括号中的“c”表示不区分大小写。您还可以使用“d”使其变音符号不敏感。这在“谓词编程指南”中有解释。