NSPredicate 与 localizedCaseInsensitiveCompare

发布于 2024-12-08 13:46:23 字数 753 浏览 0 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶ ̄淡然 2024-12-15 13:46:23

这里不需要子查询。您的整个谓词可以是:

@"activityDeleted == NO AND ANY hasMembers.memberDeleted = NO AND ANY hasMembers.city =[cd] %@", city

You don't need subquery here. Your entire predicate can instead be:

@"activityDeleted == NO AND ANY hasMembers.memberDeleted = NO AND ANY hasMembers.city =[cd] %@", city
朕就是辣么酷 2024-12-15 13:46:23

您可以在 == 上使用不区分大小写和不区分变音符号的修饰符“[cd]”

SUBQUERY(hasMembers, $sub, $sub.city ==[cd] %@)

您可以尝试在 stackoverflow 中搜索“不区分大小写的 nspredicate”,已经有几个答案 https://stackoverflow.com/search?q=case+insensitive+nspredicate

You can use the case insensitive and diacritic insensitive modifiers "[cd]" on the ==

SUBQUERY(hasMembers, $sub, $sub.city ==[cd] %@)

You might try searching stackoverflow for "case insensitive nspredicate" there are several answers already https://stackoverflow.com/search?q=case+insensitive+nspredicate

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文