Last active
October 19, 2015 12:24
-
-
Save mhuusko5/167e4949e58b509e5cf9 to your computer and use it in GitHub Desktop.
NSArray – makeObjectsPerformSelector:withEnumerableArguments:
This file contains 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 () | |
- (void)makeObjectsPerformSelector:(SEL)selector withEnumerableArguments:(id<NSFastEnumeration>)arguments { | |
for (id object in self) { | |
if (object && [object respondsToSelector:selector]) { | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[object methodSignatureForSelector:selector]]; | |
[invocation setSelector:selector]; | |
[invocation setTarget:object]; | |
if (arguments) { | |
[invocation retainArguments]; | |
int argumentIndex = 2; //Indices 0 and 1 are occupied by "self" and "_cmd" respectively | |
for (id argument in arguments) { | |
__unsafe_unretained id unretainedArgument = argument == [NSNull null] ? nil : argument; | |
[invocation setArgument:&unretainedArgument atIndex:argumentIndex++]; | |
} | |
} | |
[invocation invoke]; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment