init(format:locale:arguments:)
Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted according to given locale information. This method is meant to be called from within a variadic function, where the argument list will be available.
Declaration
convenience init(format: String, locale: Any?, arguments argList: CVaListPointer)Parameters
- format:
A format string. See 20000943 for examples of how to use this method, and TP40004265 for a list of format specifiers. This value must not be
nil. - locale:
An Nslocale object specifying the locale to use. To use the current locale (specified by user preferences), pass [Nslocale Current]. To use the system locale, pass
nil.For legacy support, this may be an instance of
NSDictionarycontaining locale information. - argList:
A list of arguments to substitute into
format.
Return Value
An NSString object initialized by using format as a template into which values in argList are substituted according the locale information in locale. The returned object may be different from the original receiver.
Discussion
The following Objective-C code fragment illustrates how to create a string from myArgs, which is derived from a string object with the value “Cost:” and an int with the value 32:
va_list myArgs;
NSString *myString = [[NSString alloc] initWithFormat:@"%@: %d\n"
locale:[NSLocale currentLocale]
arguments:myArgs];The resulting string has the value “Cost: 32\n”.
See String Programming Guide for more information.