What's the purpose of the setSelector method on the NSInvocation class?

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?

10
задан haroldcampbell 7 April 2011 в 18:58
поделиться