Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sumerman/1001923 to your computer and use it in GitHub Desktop.
Save sumerman/1001923 to your computer and use it in GitHub Desktop.
initWithTarget:selector:objects: (multiple objects, until nil) cathegory for NSInvocationOperation
@interface NSInvocationOperation (mutipleObject)
- (id)initWithTarget:(id)target selector:(SEL) objects:(id)first, ...;
@end
@implementation NSInvocationOperation (multipleObjects)
- (id)initWithTarget:(id)target selector:(SEL)sel objects:(id)first, ... {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSMethodSignature *signature = [target methodSignatureForSelector:sel];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:target];
[invocation setSelector:sel];
va_list args;
va_start(args, first);
NSUInteger i = 2;
id obj = nil;
for (obj = first; obj != nil; obj = va_arg(args, id)) {
[invocation setArgument:&obj atIndex:i];
++i;
}
va_end(args);
[invocation retainArguments];
[self initWithInvocation:invocation];
[pool release];
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment