NSPredicate 与 localizedCaseInsensitiveCompare
我有一个带有 CoreData 的应用程序,我需要使用 NSPredicate 来检索某个城市的所有联系人。
问题是“城市”可能会写成 LONDON 或 London 甚至 london。用户将输入 London 或 LoNDon 进行搜索。
我需要的是将 NSPredicate 与 localizedCaseInsensitiveCompare 结合使用,以便检索所有记录。
代码:
request.predicate = [NSPredicate predicateWithFormat:
@"activityDeleted == %@ && (SUBQUERY(hasMembers, $sub, $sub.memberDeleted == %@).@count > 0) && (SUBQUERY(hasMembers, $sub, $sub.city == %@)",
[NSNumber numberWithBool:NO],
[NSNumber numberWithBool:NO],
city];
上面的 NSPredicate 检索位于某个城市的所有具有联系人但未删除的组,但我遇到了 CaseInsensitive 问题...
我该怎么做?
谢谢,
RL
I have an App with CoreData and I need to use NSPredicate to retrieve all the contacts from a city.
The question is that "city" maybe written like LONDON or London or even london. And the user will type London to search, or LoNDon.
What I need is to use NSPredicate with localizedCaseInsensitiveCompare, so that all the records are retrieved.
Code:
request.predicate = [NSPredicate predicateWithFormat:
@"activityDeleted == %@ && (SUBQUERY(hasMembers, $sub, $sub.memberDeleted == %@).@count > 0) && (SUBQUERY(hasMembers, $sub, $sub.city == %@)",
[NSNumber numberWithBool:NO],
[NSNumber numberWithBool:NO],
city];
The above NSPredicate retrieves all the groups that have Contacts, not deleted, that are in a certain City, but I have the CaseInsensitive problem...
How can I do that?
Thanks,
RL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里不需要子查询。您的整个谓词可以是:
You don't need subquery here. Your entire predicate can instead be:
您可以在 == 上使用不区分大小写和不区分变音符号的修饰符“[cd]”
您可以尝试在 stackoverflow 中搜索“不区分大小写的 nspredicate”,已经有几个答案 https://stackoverflow.com/search?q=case+insensitive+nspredicate
You can use the case insensitive and diacritic insensitive modifiers "[cd]" on the ==
You might try searching stackoverflow for "case insensitive nspredicate" there are several answers already https://stackoverflow.com/search?q=case+insensitive+nspredicate