How can I make objc functions with multiple arguments separated by commas?

I would like to emulate the functionality of [NSArray arrayWithObjects:] , which allows me to enter arguments as follows: [MyClass doSomethingWithObjects: @"str1",@"str2",nil] . Assuming this is possible, how can I declare this?

+6
source share
1 answer

Found to be explained here: 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); } 
+12
source

Source: https://habr.com/ru/post/888760/


All Articles