ios - Filter NSArray of NSNumber with NSArray of NSNumber with NSPredicate -
i have custom class:
@interface mymodel : nsobject @property (nonatomic,strong) nsstring *id_name; @property (nonatomic,strong) nsarray *genres; @end
the genres array array of nsnumber
s. fill array mymodel
object, example:
mymodel *m = [[mymodel alloc] init]; m.id_name = @"2345"; m.genres = [nsarray arraywithobjects:[nsnumber numberwithint:3],[nsnumber numberwithint:5],nil]; mymodel *m2 = [[mymodel alloc] init]; m2.id_name = @"259"; m2.genres = [nsarray arraywithobjects:[nsnumber numberwithint:7],[nsnumber numberwithint:10],nil]; mymodel *m3 = [[mymodel alloc] init]; m3.id_name = @"25932as"; m3.genres = [nsarray arraywithobjects:[nsnumber numberwithint:7],[nsnumber numberwithint:10],[nsnumber numberwithint:15],nil]; myarray = [nsarray arraywithobjects:m,m2,m3,nil];
now want filter myarray
such genres contained within elements of array:
nsarray *a = [nsarray arraywithobjects:[nsnumber numberwithint:7],[nsnumber numberwithint:10],nil];
so, myarray
, after filtering, should contain objects m2
, m3
. can nspredicate
? if so, how? or there way?
to find objects have at least one genre in given array a
, use
[nspredicate predicatewithformat:@"any genres in %@", a];
to find objects have all genres in given array, subquery needed:
[nspredicate predicatewithformat:@"subquery(genres, $g, $g in %@).@count = %d", a, [a count]];
(the idea check if number of genres in given array equal size of array.)
Comments
Post a Comment