开发者

What is `NSInvocation`? When to use it?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜