开发者

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"...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜