Reputation: 4636
I am working with searchBarDisplayController, I have written a search predicate to search results based on what user types.
I have an Class called Contact
Class Contact
{
NSString *name;
NSString *emailId;
}
This has been added to my source to display on table
[m_contactsArray addObject:ContactObject];
//My search predicate it this way
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", searchText];
m_searchResults = [m_contactArray filteredArrayUsingPredicate:resultPredicate];
}
But this search predicate will only search name and not emailID, I want to write a search predicate which can search for characters in both name and emailID for ContactObject.
How to achieve this
Regards Ranjit
Upvotes: 0
Views: 106
Reputation: 1593
Can you please try with below predicate it may work.
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@ OR email contains[cd] %@", searchText,searchText];
Upvotes: 3