Here is the example code I saw from Apple's "Timer Programming Topics":
NSMethodSignature *methodSignature = [self
methodSignatureForSelector:@selector(invocationMethod:)];
NSInvocation *invocation = [NSInvocation
invocationWithMethodSignature:methodSignature];
[invocation setTarget:self];
[invocation setSelector:@selector(invocationMethod:)];
NSDate *startDate = [NSDate date];
[invocation setArgument:&startDate atIndex:2];
as you can see, we have to specify the invocationMethod
: once in the NSMethodSignature
, and then second time in NSInvocation
's setSelector
.
To me, this seems redundant, is there any reason why Apple design like this?
[invocation setSelector:@selector(invocationMethod:)];
is called? This way, we don't need to create aNSMethodSignature
object ahead. – Vadose