objective c - Variadic method in Swift -


objective c code:

- (instancetype)initwithints:(int32_t)int1, ... {     va_list args;     va_start(args, int1);     unsigned int length = 0;     (int32_t = int1; != -1; = va_arg(args, int)) {         length ++;     }     va_end(args);     ...     ...     return self; } 

this code used count numbers of method's parameters.

swift code:

convenience init(ints: int32, _ args: cvarargtype...) {     var length: uint = 0     self.init(length: args.count)     withvalist(args, { _ in         // how increase length' value in loop?     }) } 

what's best practise use withvalist loop through argument list cvalistpointer? appreciated.

how just

convenience init(args: int...) {   return args.count } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -