Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhuusko5/167e4949e58b509e5cf9 to your computer and use it in GitHub Desktop.
Save mhuusko5/167e4949e58b509e5cf9 to your computer and use it in GitHub Desktop.
NSArray – makeObjectsPerformSelector:withEnumerableArguments:
@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