开发者

What is `NSInvocation`? When to use it?

开发者 https://www.devze.com 2022-12-24 07:18 出处:网络
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.

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

精彩评论

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