I’ve seen it claimed that the following are ‘pretty much equivalent’:
foo([NSString stringWithString:@'blah']) # version 1 foo([[[NSString alloc] initWithString:@'blah'] autorelease]) # version 2
Are the above in fact literally equivalent or are there any subtle differences? What are reasons to prefer one or the other?
The two are functionally equivalent, but as rpetrich observes, may operate ever-so-slightly differently internally. This shouldn’t matter to you, use whichever seems more convenient to you. Furthermore, while there is a minute performance difference, it is highly unlikely to matter to your application in practice.
But all this misses a crucial point: both are pointless. By writing @’foo’ you already have a fully functional NSString object. There is no need to mess around with extra methods to duplicate the string; it is quicker and simpler to just do: