As NSString
strings are immutable, what is the value of the stringWithString:
class method?
I get the utility when used with NSMutableString
, I just didn't see the utility with the NSString
class.
As NSString
strings are immutable, what is the value of the stringWithString:
class method?
I get the utility when used with NSMutableString
, I just didn't see the utility with the NSString
class.
FYI, now that we are compiling with ARC enabled, you don't have to manually release at all, ARC will insert the release calls during compile time. So how is it still different? stringWithString is still added to the autorelease pool which gets drained sometime in the future (unless you created your own autorelease pool). initWithString will have a release call right before the function ends, so if you didn't retain it somewhere in the method, you can be sure that the string is destroyed by the end of the function call. This gives you a tighter control on the memory management as opposed to using autoreleased objects.