What is开发者_如何转开发 NSInvocation
? When and how to use it?
NSInvocation's a reification of a message send. In other words, it's an object that represents the sending of a message.
Say your class Foo has a method called -[Foo foo], and a method like this:
-(void)doSomething {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector: @selector(foo)]];
[inv setTarget: self];
[inv invoke];
}
Then saying [self foo] is functionally the same thing as saying [self doSomething].
Why would you want to do this? The CubePuzzle sample app gives one idea. Another might be to schedule a message send to take place in the future, say as triggered by an NSTimer.
精彩评论