Udai kumar Udai kumar - 4 months ago 9
iOS Question

How to get unmatched elements in an nsmutablearray

I have a

NsMutableArray
. I filtered matched data with
NSPredicate
but i want that array element which is not matched.

Can anyone help me.

Answer

You can use NOT with the predicate for that

NSArray *arrValues = [NSArray arrayWithObjects:@"Hello",@"Hello One",@"Good Morning", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF CONTAINS %@)",@"Hello"];  
NSArray *arrFiltered  = [arrValues filteredArrayUsingPredicate:predicate];
NSLog(@"%@",arrFiltered);

Output

(
   "Good Morning"
)