Skip to content

Instantly share code, notes, and snippets.

@AdityaDeshmane
Created December 2, 2015 13:07
Show Gist options
  • Save AdityaDeshmane/23f8b59c3180c977c56b to your computer and use it in GitHub Desktop.
Save AdityaDeshmane/23f8b59c3180c977c56b to your computer and use it in GitHub Desktop.
/* Input Data sample
SWSearchContact *contactModel = [[SWSearchContact alloc] init];
contactModel.arrPhoneNumbers = [arrPhoneNumbers copy];
contactModel.strFirstName = firstName ? firstName : @"";
contactModel.strMiddleName = middleName ? middleName : @"";
contactModel.strLastName = lastName ? lastName : @"";
[_arrMutContacts addObject:contactModel];
*/
NSArray *filteredArray = nil;
NSPredicate *predicate;
//E.g 1 : Search on string
predicate = [NSPredicate predicateWithFormat:@"strFirstName contains[c] %@ OR strMiddleName contains[c] %@ OR strLastName contains[c] %@",_strName,_strName,_strName];
//E.g 2 : Search inside array for string
predicate = [NSPredicate predicateWithFormat:@"ANY SELF.arrPhoneNumbers contains[c] %@", _strPhoneNumber];
filteredArray = [_arrMutContacts filteredArrayUsingPredicate:predicate];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment