I don't understand why we have to call the setSelector
method on NSInvocation
objects when that information is already passed via the invocationWithMethodSignature
.
To create an NSInvocation
object we do the following:
SEL someSelector;
NSMethodSignature *signature;
NSInvocation *invocation;
someSelector = @selector(sayHelloWithString:);
//Here we use the selector to create the signature
signature = [SomeObject instanceMethodSignatureForSelector:someSelector];
invocation = [NSInvocation invocationWithMethodSignature:signature];
//Here, we again set the same selector
[invocation setSelector:someSelector];
[invocation setTarget:someObjectInstance];
[invocation setArgument:@"Loving C" atIndex:2];
Notice that we passed the selector to [SomeObject instanceMethodSignatureForSelector: someSelector];
and again to [invocation setSelector:someSelector];
.
Is there something I'm missing?
signature = [SomeObject instanceMethodSignatureForSelector:someSelector];
should be eithersignature = [[SomeObject class] instanceMethodSignatureForSelector:someSelector]; or signature = [SomeObject methodSignatureForSelector:someSelector];
– Terceira