I'm trying to use an operation object to create a thread. From the
looks of the NSInvocationOperation documentation I should use
initWithTarget:selector:object, which object is the argument to be
passed. Is it possible to pass multiple args? I can't figure it out:(
Thanks in advance for any suggestions!
For a multi-argument method, you'll want to construct your
NSInvocation first, then use initWithInvocation: to create your
NSInvocationOperation from that.
The following is an example of how to construct an NSInvocation:
SEL theSelector = @selector(yourMethodWithString:number:)
NSMethodSignature * sig = [self methodSignatureForSelector:theSelector];
NSInvocation * theInvocation = [NSInvocation
invocationWithMethodSignature:sig];
[theInvocation setTarget:self];
[theInvocation setSelector:theSelector];
NSString *firstArgument = [NSString stringWithString:@"Test"];
NSNumber *secondArgument = [NSNumber numberWithInt:2];
[theInvocation setArgument:&firstArgument atIndex:2];
[theInvocation setArgument:&secondArgument atIndex:3];
[theInvocation retainArguments];
For more on NSInvocations, I direct you to Scott Stevenson's excellent
post on the topic:
http://theocacao.com/document.page/264
______________________
Brad Larson, Ph.D.
Sunset Lake Software
http://www.sunsetlakesoftware.com