Created
July 15, 2009 13:05
-
-
Save atnan/147686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSArray(Filtering) | |
- (NSArray*)arrayByMappingArrayUsingSelector:(SEL)selector, ... { | |
NSInvocation* invocation; | |
va_list arguments; | |
if (selector && [self lastObject]) { | |
va_start(arguments, selector); | |
invocation = [NSInvocation invocationUsingSelector:selector onTarget:[self lastObject] argumentList:arguments]; | |
va_end(arguments); | |
} | |
NSMutableArray *filteredArray = [NSMutableArray array]; | |
BOOL returnValue; | |
for(id object in self) { | |
[invocation invokeWithTarget:object]; | |
[invocation getReturnValue:&returnValue]; | |
if(ret) [filteredArray addObject:object]; | |
} | |
return filteredArray; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment