lu yuan lu yuan - 1 year ago 54
iOS Question

Filter Array with dictionaries using NSPredicate

There is an Array with each element being a


NSMutableArray *mutArr = [NSMutableArray array];

for (Person *person in persons) {
NSDictionary *dict = [[NSDictionary alloc], @"name",, @"email", nil];
[mutArr addObject:dict];

self.arr = [[NSArray alloc] initWithArray:mutArr];

How to filer the
with name or email contains string
@"filter string"
by using

Thanks in advance!

Nit Nit
Answer Source

Please see the below may help you...

 NSArray *array = [NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:@"filter string" forKey:@"email"]];   // you can also do same for Name key... 
    NSArray *filteredarray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(email == %@)", @"filter string"]];

I hope it will help you...enjoy