在搜索显示控制器中分组
在我的核心数据应用程序中,我有一个实体 Person,其名称作为属性。 我使用以下谓词逻辑来搜索名称。 当我们用单词搜索时它会显示名称。 好吧,但我想要两组搜索名称作为
包含名称中任何位置的单词
名称以单词开头。
两个组我都想要。如何?
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
Word containing anywhere in the name
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的例子应该适用于#1。
单词位于名称中的任何位置:
名称以单词开头:
Your example should work for #1.
word is anywhere anywhere in the name:
name starts with the word:
我认为你这里有 2 个选择:
1)
- (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest ManagedObjectContext:(NSManagedObjectContext *)contextsectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name
passsectionNameKeyPath:
按您想要分组的内容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
passsectionNameKeyPath:
by what you want to group2) group after selecting
- (NSArray *)executeFetchRequest:(NSFetchRequest *)request error:(NSError **)error