我有一个采用类似这样的可变参数的方法,参数以 nil 结尾。
-(void)manyParams:(NSString *)st, ... {
va_list argList;
va_start(argList,st);
id obj;
while ((obj = va_arg(argList, id))) {
NSLog(@"%@",obj);
}
va_end(argList);
return;
}
我可以这样直接调用
[self manyParams:@"one",@"two",@"three",nil];
如果我使用NSInvocation
类来调用 manyParams 那么我该怎么做
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self];
[invocation setSelector:@selector(manyParams:)];
///NSString *one = @"one";
///[invocation setArgument:&one atIndex:2]; //////How to pass variable arguments like @"one",@"two",@"three", nil
[invocation invoke];