1

How can i make method with parameter is unlimited array like this :

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
                initWithTitle:@"Test Title"
                delegate:self
                cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:@"Destructive"
                otherButtonTitles: @"abc", @"xyz",
                nil] autorelease];

In above code, parameter otherButtonTitles can have unlimit number of NSString like "abc", "xyz",.. Can do this with other type of parameter?
Thanks in advance!.

anhduongt
  • 1,119
  • 2
  • 12
  • 17

1 Answers1

1

You can do it with any type of object.

In the header

- (void)myMethod:(NSObject *)first, ... NS_REQUIRES_NIL_TERMINATION;

Implementation

- (void)myMethod:(NSObject *)first, ... {
    va_list args;
    va_start(args, first);
    for (NSObject *o = first; o!=nil; o = va_args(args,NSObject*)) {
        NSLog(@"Here's your next object: %@", o);
    }
    va_end(args);
}