在搜索显示控制器中分组

发布于 2024-12-20 01:54:22 字数 410 浏览 2 评论 0原文

在我的核心数据应用程序中,我有一个实体 Person,其名称作为属性。 我使用以下谓词逻辑来搜索名称。 当我们用单词搜索时它会显示名称。 好吧,但我想要两组搜索名称作为

  1. 包含名称中任何位置的单词

  2. 名称以单词开头。

两个组我都想要。如何?

NSString *searchfilter = [NSString stringWithFormat:@"*%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];

In my Core Data app, I have an entity Person with names as attribute.
I used following predicate logic to search the names.
It displays names when we search with a word.
well but I want two groups of searched names as

  1. Word containing anywhere in the name

  2. Name starts withe the word.

both groups I want. How?

NSString *searchfilter = [NSString stringWithFormat:@"*%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

笑脸一如从前 2024-12-27 01:54:22

你的例子应该适用于#1。

单词位于名称中的任何位置:

NSString *searchfilter = [NSString stringWithFormat:@"*%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];

名称以单词开头:

NSString *searchfilter = [NSString stringWithFormat:@"%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];

Your example should work for #1.

word is anywhere anywhere in the name:

NSString *searchfilter = [NSString stringWithFormat:@"*%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];

name starts with the word:

NSString *searchfilter = [NSString stringWithFormat:@"%@*",savedSearchTerm_];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"word like[c] %@", searchfilter];
[fetchRequest setPredicate:filter];
梨涡 2024-12-27 01:54:22

我认为你这里有 2 个选择:

1) - (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest ManagedObjectContext:(NSManagedObjectContext *)contextsectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name pass sectionNameKeyPath: 按您想要分组的内容

2) 选择 - (NSArray *)executeFetchRequest:(NSFetchRequest *)请求错误:(NSError **)错误

i think you have 2 options here:

1) - (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext:(NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name pass sectionNameKeyPath: by what you want to group

2) group after selecting - (NSArray *)executeFetchRequest:(NSFetchRequest *)request error:(NSError **)error

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