It is easy to find that the Cocoa Foundation provides some variable parameter methods, such:
NSLog (NSString * format ,...)
In actual programming practices, we also need to implement variable parameters. In Objc, it relies on the native C library for implementation.
See the example:
-() DoLog :( NSString * NSMutableArray * arr = NSString * (arg = va_arg (argList, NSString * (NSString * str NSLog (} View Code
The following describes the C methods used in the code snippet;
1. va_list argList: defines a pointer to a variable number of parameter lists;
2. va_start (ap, param) param is a fixed parameter before the first optional parameter. va_start points the pointer to the first optional parameter;
3. va_arg (ap, type): return the parameter specified by the pointer ap in the parameter list. The return type is type and the pointer ap points to the next parameter in the parameter list;
4. va_end (ap) clears the parameter list. The reset parameter ap is invalid.