How to “pass on” a variable number of arguments to NSString's +stringWithFormat:

前端 未结 1 1428
猫巷女王i
猫巷女王i 2020-12-29 20:06

I would like to write a function in Objective-C such as the one below, that takes a variable number of arguments, and passes those arguments on to +stringWithFormat:

相关标签:
1条回答
  • 2020-12-29 20:34

    initWithFormat:arguments:

    NSString *estr(NSString *format, ...) {
        va_list args;
        va_start(args, format);
        NSString *s = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
        va_end(args);
        return s;
    }
    

    they don't seem to have a convenience constructor "stringWith..." version

    0 讨论(0)
提交回复
热议问题