NSInvocation* storeMessage(id target, SEL selector, ...) { NSMethodSignature *sig = [[target class] instanceMethodSignatureForSelector:selector]; NSInvocation *nsInvocation = [NSInvocation invocationWithMethodSignature:sig]; [nsInvocation setTarget:target]; [nsInvocation setSelector:selector]; id eachObject; int cur = 2; va_list args; va_start(args, selector); while( eachObject = va_arg(args, id) ) { [nsInvocation setArgument:&eachObject atIndex:cur]; cur++; } va_end(args); [nsInvocation retain]; return nsInvocation; }
NSInvocation* inv = storeMessage(targetObject, @selector(functionToCall), arg1, arg2, arg3, nil); [inv invoke];
Copyright © Scott Stevenson 2004-2015
by Trenton Ahrens — Jun 25
NSInvocation* storeMessage(id target, SEL selector, ...) { NSMethodSignature *sig = [[target class] instanceMethodSignatureForSelector:selector]; NSInvocation *nsInvocation = [NSInvocation invocationWithMethodSignature:sig]; [nsInvocation setTarget:target]; [nsInvocation setSelector:selector]; id eachObject; int cur = 2; va_list args; va_start(args, selector); while( eachObject = va_arg(args, id) ) { [nsInvocation setArgument:&eachObject atIndex:cur]; cur++; } va_end(args); [nsInvocation retain]; return nsInvocation; }
use:
NSInvocation* inv = storeMessage(targetObject, @selector(functionToCall), arg1, arg2, arg3, nil); [inv invoke];