objective-c - iOS 深浅拷贝?
PHP中文网
PHP中文网 2017-05-02 09:36:07
0
3
898
NSString *i = @"1";
NSString *j = [i mutableCopy];
NSLog(@"i=%p,j=%p",i,j);

打印地址不一样,由此可见是内容拷贝
继续
i = @"2";
NSLog(@"i=%@,j=%@",i,j);
那么问题来了,为什么j的值还是1?
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
Peter_Zhu

Content copy is a deep copy. The new j generated is a new object and has nothing to do with i. So changing i will not affect j.

为情所困

The addresses are different, which means they are two objects. So the question is, why are the values ​​​​between two independent objects still related?

洪涛

ok, let me check the information first

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template