Elegant way to get all objects of a specific type in an Objective-C array

Posted by Ranking Stackingblocks on Stack Overflow See other posts from Stack Overflow or by Ranking Stackingblocks
Published on 2010-04-23T14:00:57Z Indexed on 2010/04/23 14:03 UTC
Read the original article Hit count: 248

Filed under:
|
|

I know I can do

for (id obj in array)
{
    if ([obj isKindOfClass:[Elephant class]])
        [elephants addObject:obj];
}

but I feel there must be a more elegant way of doing this. I've looked at filtering arrays but can't come up with a good predicate. Thoughts?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about arrays