Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

iOS 深浅拷贝?

NSString *i = @"1";
NSString *j = [i mutableCopy];
NSLog(@"i=%p,j=%p",i,j);

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

内容 拷贝,就是深拷贝,生成新的j是一个新的对像,和i没有关系 。所以改变i,不会影响j的。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...