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
Post a Comment