Ns_requires_nil_termination, for compile-time non-NIL end checks-(void) Mutableargumentsfunction: (NSString *) arg1, ... ns_requires_nil_termination{ //defines a pointer to an optional parameter list va_list args; Gets the address of the first optional parameter, at which point the argument list pointer points to the first optional parameter in the function argument list va_start (args, arg1); if (arg1) { //iterates through the parameters in the parameter list and causes the argument list pointer to point to the next parameter in the parameter list nsstring *nextarg; while ((Nextarg = Va_arg (args, NSString *)) { NSLog (@ "ARG:%@", Nextarg);} } Ends the Get (empty argument list) of the mutable parameter va_end (args);}
Special attention:
1. variable parameters can only be the last one in all parameters
2.ns_requires_nil_termination, for compile-time non-NIL end inspection
Application Scenarios:
1. Please refer to this method when rewriting Uialertview
2. Rewrite NSLog
Declaration and implementation of variable parameter methods in IOS