My arrays arr
originally contains following
[A,B,C,D,E,F,G];
Now I want to remove A and B and C and I could do it like following
[arr enumerateObjectsUsingBlock:^(NSString *name, NSUInteger idx, BOOL *stop) {
if ( [name isEqualToString:@"A"] || [name isEqualToString:@"B"] || [name isEqualToString:@"C"]);
[arr removeObject:name];
}];
Question : is it possible to do it using nsexpression. It sounds like to define an nsexpression contains A and B and C, then we delete elements based on the nxpression.
Any ideas how to achieve this. All comments are welcomed here. Thanks.
Instead of using NSExpression
directly, consider filteredArrayUsingPredicate:
or, for NSMutableArray
, filterUsingPredicate:
. This will either return a new array filtered by the predicate, or the same array, mutated according to the predicate.
Also, it is not a real good idea to mutate your collection while enumerating.