Tag: 可变参数

在ARC中伪造va_list

我需要在iOS应用程序中创build一个虚拟的va_list传递给一个NSString的initWithFormat:arguments: function,这是我的代码: NSArray *fixedArguments = [[NSArray alloc] initWithArray:arguments]; NSRange range = NSMakeRange(0, [fixedArguments count]); va_list fakeArgList = (va_list)malloc(sizeof(NSString *) * [fixedArguments count]); __unsafe_unretained id *ptr = (__unsafe_unretained id *)fakeArgList; [fixedArguments getObjects:ptr range:range]; content = [[NSString alloc] initWithFormat:outputFormat arguments:(va_list)fakeArgList]; free(fakeArgList); 编译器会在cast行上抱怨这条消息: error: cast of a non-Objective-C pointer type 'va_list' (aka 'char *') to '__unsafe_unretained id *' […]