How can i make a class method with variable length parameters, in Objective-C?
For example, a method like -arrayWithObjects:
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
Take a look at varargs, e.g.: Apple Technical Q&A QA1405. It shouldn't matter whether the method is a class method or not.
What you need is a variadic function. These functions take a flexible number of arguments, like NSLog, [NSArray arrayWithObjects:...], etc.
See this tutorial:
http://www.numbergrinder.com/node/35
Copied from my answer here: Obj-C, trying to write an alternative to NSLog, but I want my function to concatenate like NSLog?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With