NSPredicate - 针对多种情况的不区分大小写的过滤 [英] NSPredicate - case insensitive filtering for multiple conditions

查看:377
本文介绍了NSPredicate - 针对多种情况的不区分大小写的过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下NSPredicate进行过滤,

I'm using following NSPredicate for filtering,

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@  )OR (UserName CONTAINS %@ )  ", myText,myText,myText];
NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate];

它工作正常,但它区分大小写。我需要过滤应该不区分大小写。

It works fine, but it's case-sensitive. I need the filtering should be case insensitive.

我试过,

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.'

我无法理解这个答案。任何人都可以建议我在上面的过滤中应该更改什么?

I can't understand what it was mentioned in this answer. Can anyone suggest what should I change here in the above filtering?

推荐答案

替换所有 CONTAINS with CONTAINS [c] 。方括号中的c表示不区分大小写。您也可以使用d使其变音符号不敏感。这在谓词编程指南中有解释。

Replace all CONTAINS with CONTAINS[c]. The "c" in square brackets means case insensitive. You can also use a "d" to make it diacritic insensitive. This is explained in the "Predicate Programming Guide".

这篇关于NSPredicate - 针对多种情况的不区分大小写的过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆