我想模仿[NSArray arrayWithObjects:]的功能,这允许我以这种方式输入争论:[MyClass doSomethingWithObjects:@“str1”,@“str2”,nil].假设这是可能的,我该如何声明?
解决方法
发现它在这里解释:
http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
//interface: - (void)foo:(NSString *)firstString,... NS_REQUIRES_NIL_TERMINATION; //implementation: - (void)foo:(NSString *)firstArg,... { va_list args; va_start(args,firstArg); for (NSString *arg = firstArg; arg != nil; arg = va_arg(args,NSString*)) { [self bar:arg]; } va_end(args); }