Filtering data using UISearchDisplayController

117 views Asked by At

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

1

There are 1 answers

0
Susim Samanta On BEST ANSWER

Can you please try with below predicate it may work.

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@ OR email contains[cd] %@", searchText,searchText];