Created
June 1, 2011 07:25
-
-
Save sumerman/1001923 to your computer and use it in GitHub Desktop.
initWithTarget:selector:objects: (multiple objects, until nil) cathegory for NSInvocationOperation
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
@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