ER: Add +[NSString stringWithFormat:arguments:]

Number:rdar://7025084 Date Originated:2009-07-01
Status:Closed Resolved:Behaves Correctly
Product:NSString Product Version:
Classification:Enhancement Reproducible:Not Applicable
NSString has a bevy of convenience constructors corresponding to most of its -init... methods. One that is conspicuously missing is a wrapper for -[NSString initWithFormat:arguments:], which accepts a va_list as the second argument. This means that anytime I want to create a throwaway string with a va_list, I have to go through the alloc/init/autorelease song and dance. This happens a lot for log statements, and also when integrating with legacy code, which makes the experience all the more aggravating. (I would use +stringWithFormat:, but inside a variadic function I can't really pass the varargs along to someone else without wrapping them in a va_list first.)

This would be a very close cousin to +stringWithFormat: and both are used in the context of variadic functions/methods. I know we always want to keep API simple, but adding this method would be extremely useful when needed, and is very low risk. A related problem requesting this <rdar://problem/6860785> also mentions that GNUstep has this method, and I agree that compatibility would be useful. I've been bitten by the lack of this method several times over the last 2 years, and I'm not the only one who'd like to see this feature, or gets confused at the lack of such a method. See this related Stack Overflow question:


Official response: "I wouldn't think initWithFormat:arguments: is a popular enough initializer to really deserve a convenience method."

By quinntaylor at March 6, 2010, 11:35 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!