Reputation: 185
I would like to know if there is a way to search for a range of values in NSArray! What I mean is something like clause in SQL. Or maybe checking if some of elements of one NSArray are contained in another. Hope this explains my question. Thank you.
Upvotes: 0
Views: 73
Reputation: 125007
There are several ways to search through an array. The one that comes closest to what you seem to be describing for searching is the -filteredArrayUsingPredicate:
method. NSPredicate
gives you a large variety of operators for examining data, and predicates can be combined into compound predicates so that you can do searches such as "lastName like 'smith' and income > 75000". Read more about NSPredicate on NSHipster (or in Apple's docs, of course).
If you want to find common elements between two arrays, an easy technique is to convert both arrays to sets and find their intersection:
NSMutableSet *intersection = [NSMutableSet setWithArray:array1];
[intersection intersectSet:[NSSet setWithArray:array2]];
Upvotes: 1