One Quickie


Using NSInvocation (General->General)
When you have a target and a selector, it's pretty easy to invoke the selector on the target if you're passing one or two parameters, with performSelector:, performSelector:withObject:, and so on. If you need to pass three arguments, or things that aren't objects, then you need to use NSInvocation.

In this case, the selector being called takes two arguments, one of which is an object, the other is an NSTimeInterval. The atIndex: jazz starts with 2 so that the self parameter and the selector can be passed to the method.

  NSMethodSignature *signature = [target_ methodSignatureForSelector:selector_];

  NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
  [invocation setSelector:selector_];
  [invocation setTarget:target_];
  [invocation setArgument:&self
              atIndex:2];
  [invocation setArgument:&lastWait_
              atIndex:3];

  [invocation invoke];



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com