I was just curious, is there any difference between the following two codes?
NSString *aString = [NSString stringWithString:@"a string"];
NSString *aString = @"a string";
I wonder what exactly is going on when you do the latter way.
I was just curious, is there any difference between the following two codes?
NSString *aString = [NSString stringWithString:@"a string"];
NSString *aString = @"a string";
I wonder what exactly is going on when you do the latter way.
Both point to a literal string created at compile time.
Even though stringWithString suggest it's autoreleased, a literal string will never get released.
See my related post here:
Difference between NSString literals
From the apple docs @ https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/CreatingStrings.html
Such an object is created at compile time and exists throughout your program’s execution. The compiler makes such object constants unique on a per-module basis, and they’re never deallocated, though you can retain and release them as you do any other object.