NSString is really Immutable?
Why when I code I can do:
NSString *test;
test = @"stack";
test = @"overflow";
without any problems, NSString
is not开发者_如何转开发 supposed to be immutable?
It is immutable. You're not changing the underlying string with those statements, you're creating/using a brand new string. The pointer itself can change as often as you want but that's not the string.
The string object is immutable. You are only changing the pointer to a different string.
In your code you just "forget" about the old value (stack) and create a new string instance and fill it with "overflow"...
精彩评论