NSString真的是不可变的吗? [英] NSString is really Immutable?
本文介绍了NSString真的是不可变的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我可以编码:
NSString *test;
test = @"stack";
test = @"overflow";
没有任何问题, NSString
是否应该是不变的?
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.
这篇关于NSString真的是不可变的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文