I’m writing a bit of code doing string manipulation. In this particular situation, appending “?partnerId=30” to a URL for iTunes Affiliate linking. This is a raw string and completely static. I was thinking, is it better to do:
urlString = [urlString stringByAppendingFormat:@"%@", @"?partnerId=30"];
Or:
urlString = [urlString stringByAppendingFormat:@"%s", "?partnerId=30"];
I would think it’s better to not instantiate an entire Objective-C object, but I’ve never seen it done that way.
String declared using the @”” syntax are constant and will already exist in memory by the time your code is running, thus there is no allocation penalty from using them.
You may find they are very slightly faster, as they know their own length, whereas C strings need to be looped through to find out their length.
Through you’d gain a more tangible performance improvement (though still tiny) from not using a format string: