多参数接收

声明一个方法

- (instancetype)initWithButtonTitles:(nullable NSString*)buttonTitles,...NS_REQUIRES_NIL_TERMINATION;

方法的实现

- (instancetype)initWithButtonTitles:(nullable NSString*)buttonTitles,...NS_REQUIRES_NIL_TERMINATION
{
    self = [super init];
    if (self) {       
        NSMutableArray* btnTitles = [NSMutableArray new];
        if (buttonTitles) {
            [btnTitles addObject:buttonTitles];
            va_list arglist;
            va_start(arglist,buttonTitles);
            NSString *arg;
            while ((arg = va_arg(arglist, NSString *)))
            {
                NSLog(@"%@", arg);
                [btnTitles addObject:arg];
            }
            va_end(arglist);
        }
    }
    return self;
}

你可能感兴趣的:(多参数接收)