Variable length parameters in Objective-C
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];
3 Solutions Collect From Internet About “Variable length parameters in Objective-C”
What you need is a variadic function. These functions take a flexible number of arguments, like
[NSArray arrayWithObjects:...], etc.
See this tutorial:
Copied from my answer here: Obj-C, trying to write an alternative to NSLog, but I want my function to concatenate like NSLog?
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.
Methods that take variable arguments are known as variadic methods. The “…” is the variable argument.
For example, your function declaration would be:
- (void)specialWithX:(NSInteger)x y:(NSInteger)y, ...;
For additional information take a look at Variable argument lists in Cocoa
- Why can't I pass an optional Swift String to C function that allows NULL pointers?
- When do I need to set the contentsScale property of a CALayer?
- increase uitableviewcell height simultaneously increasing the inner UITextView
- Delivery of auto-renewing subscriptions for iOS
- Change Text or Background of UIButton after a tap
- 'The 'Pods' target has transitive dependencies that include static binaries' when installing GCM
- iOS 8 youtube video embed
- How to hide UINavigationBar 1px bottom line
- xcodebuild failure clang:error no such file or directory:
- All notifications disappearing after opening one of them
- iOS 7 UINavigationBar appearance not working first time…
- Swift, add swipe to delete UITableViewCell
- Drawing a dashed line with CGContextSetLineDash
- PhoneGap and iPhone 5: Remove top and bottom black stripes
- How to set Image in Tabbar not Tint color in ios?