I want to filter an array of User
objects (User
has fullname
, user_id
and some more attributes..) according to firstName
or lastName
that begin with some string.
I know how to filter according to one condition:
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"firstName BEGINSWITH[cd] %@", word];
NSArray* resArr = [myArray filteredArrayUsingPredicate:predicate];
this will give me all the users that has a firstName that starts with "word".
But what if I want all the users that has a firstName or lastName that start with "word"?
Use like this:
You can use the class
NSCompoundPredicate
to create compound predicates.this is one way that I like doing.
Or you can do ...
either will work.