问题
We need to format a string, but for some localisations we won't output all parameters. But it seems that it doesn't work to output less parameters than passed:
NSString *string = [NSString stringWithFormat: @"%2$@", @"<1111>", @"<22222>"];
NSLog(@"String = %@", string);
Outputs
String = <1111>
although i output the second parameter. Is this a bug or a feature?
回答1:
according to the related industrial standard, IEEE specification:
When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, are specified in the format string.
which means in other words, you must use the first %1$@ parameter in your string formatter somewhere before you address to use the second one – so, it is not a bug at all.
来源:https://stackoverflow.com/questions/34657641/nsstring-stringwithformat-less-parameters