Consider the arrays below. The arrays contain objects of type 'Alpha'. We only care about the property username
which is of type NSString
.
NSArray *some_usernames = @[ <multiple values of type Alpha> ]
NSArray *all_usernames = @[ <multiple values of type Alpha> ]
I basically want a list of all the usernames that are not in the array some_usernames
, i.e.
NSArray *remaining_usernames = @[ <all_usernames but not in some_usernames> ];
The way I would intend to do is:
NSPredicates *predicates;
for (Alpha *alpha in some_usernames)
{
predicate = [predicate with @"username != %@", alpha.username];
predicates.add(predicate)
}
create compound predicate
filter all_usernames
But this feels like a bad way of doing this. Is there a way to do this in two lines? I have seen it before but I can't point to the code reference anymore.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…