5 Replies Latest reply: Oct 20, 2008 4:07 AM by just.do.it
wallclimber21 Level 1 (0 points)
This feels like a really dumb question, but the docs aren't exactly clear about this: how are they different? Is stringWithFormat simply a wrapper around initWithFormat that does an additional alloc / autorelease?

This actually came up in the following: I have a piece of code that creates an identifier string for an object:

Like this:

+(NSString *)createDictionaryKeyFromABC:(int)a b:(int)b c:(int)c
NSString *key = [[NSString alloc] initWithFormat: @"%d:%d:%d", a, b, c];
return key;

Usually, I only need to use those elements for a short time, so I find myself doing ... release right after usage. Is this a place where stringWithFormat would be better?


PC, Mac OS X (10.5.4)