Why when I code I can do:
NSString *test;
test = @"stack";
test = @"overflow";
without any problems, NSString
is not supposed to be immutable?
Why when I code I can do:
NSString *test;
test = @"stack";
test = @"overflow";
without any problems, NSString
is not supposed to be immutable?
The string object is immutable. You are only changing the pointer to a different string.
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.
In your code you just "forget" about the old value (stack) and create a new string instance and fill it with "overflow"...
Duplicate of the final word on nsstrings mutable and immutable ?
found though the first hit of Google(NSString immutable)