我有一个方法,它接收可变参数,格式类似于这样,参数以 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];