On Objective-C, I can do something like:
UIAlertView *av = [[UIAlertView alloc] initWith ... otherButtonTitles:@"button1", @"button2", nil];
Can I make a method for myself which takes as an argument these parameters separed by a comma… And if so how?
Declare the method like this in your
@interface:Then in the
@implementationyou would define it like this:The
va_list,va_start,va_argandva_endare all standard C syntax for handling variable arguments. To describe them simply:va_list– A pointer to a list of variable arguments.va_start– Initializes a va_list to point to the first argument after the argument specified.va_arg– Fetches the next argument out of the list. You must specify the type of the argument (so that va_arg knows how many bytes to extract).va_end– Releases any memory held by the va_list data structure.Check out this article for a better explanation – Variable argument lists in Cocoa
See also: “IEEE Std 1003.1 stdarg.h”
Another example from the Apple Technical Q&A QA1405 – Variable arguments in Objective-C methods: