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];
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];