The predicate will be something like
Class ec = [Elephant class];
NSPredicate *elePred = [NSPredicate predicateWithFormat:@"class==%@", ec];
NSArray *elephants = [array filteredArrayUsingPredicate:elePred];
or
NSPredicate *elePred = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", ec];
I found that the predicates are pretty, uh ... we say "heavy." I would prefer your code.
If you just want to enliven your life a bit, you can use blocks to add a bit of concurrency ...
NSMutableArray *results = [NSMutableArray array];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
if([obj isKindOfClass:[Elephant class]])
[results addObject:obj];
}];
source
share