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
- How to save integer value to NSuserDefault like sqlite?
- Selectors in Objective C
- Detect collision of two UIView's in swift
- Swift how to use enum to get string value
- Extend existing protocols to implement another protocol with default implements
- Cocoa Threadsafe Mutable Collection Access
- how to add 2 textfields togethers as int (swift3)
- Does the App Store version of Xcode cleanly replace the non-App-Store version?
- Dismissing a UIDocumentInteractionController in some cases will remove the presenting view controller's views in IOS 7 iPad
- How to require a minimum text length in UITextField before enabling keyboard return key
- Issue with iphone sdk 4.2.1
- Compatibility problem with .xcdatamodeld between Xcode 4.1 (Lion) and Xcode 3.2.5 (snow leopard)
- Is it possible to reduce background noise while streaming audio on the iPhone?
- Change views when iPhone is rotated?
- How do I use SWRevealViewController with unwind segues?