NSInvocation使用还是挺简单的,只是还是有很多开发者不知道他是干嘛的,这里做个比较。
NSInvocation能做啥?
在iOS中如果调用某个对象的消息我们经常使用系统提供的performSelector方法
performSelector: withObject:
performSelector:
...
performSelector这玩意是好,但蛋疼的是如果是参数是多个时,咋办?这时NSInvocation就上场了,所以NSInvocation的作用也是用于调用某个对象的消息,且不限制于被调用消息参数的个数。
例子:
-(void)invocation{//方法签名NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:@selector(calWith:andB:)];if (signature) {NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];invocation.target = self;invocation.selector = @selector(calWith:andB:);int a=10,b=20;//自定义参数索引从2开始(atIndex?