之前都是靠记忆来维持copy和strong 也有问过我 。 我自己说起来才感觉都说不很清楚
通过简单都代码来验证一下 。 有时候花点时间验证一下才能让思路更加清晰
NSMutableString * mustr = [NSMutableString stringWithString:@"good"];
self.str = mustr;
self.fuzhiString = mustr;
NSLog(@"self.str is (%@) ==== str,self.fuzhiString is (%@)",self.str,self.fuzhiString);
NSLog(@"self.str *p is (%@) ==== str,self.fuzhiString *p is (%@)",self.str,self.fuzhiString);
注释:打印结果 == self.str is (good) ==== str,self.fuzhiString is (good)
self.str *p is (0x600000059350) ==== str,self.fuzhiString *p is (0xa000000646f6f674)
[mustr appendString:@"night"];
NSLog(@"self.str is (%@) ==== str,self.fuzhiString is (%@)",self.str,self.fuzhiString);
NSLog(@"self.str *p is (%@) ==== str,self.fuzhiString *p is (%@)",self.str,self.fuzhiString);
注释:打印结果 ==self.str is (goodnight) ==== str,self.fuzhiString is (good)
self.str *p is (0x600000059350) ==== str,self.fuzhiString *p is (0xa000000646f6f674)
打印结果: copy修饰的属性为深copy(开辟一个新内存指向一个新的值)
strong修饰的属性为浅copy(跟着mustr的值的改变而改变);
同时表明字符串为了防止不经意的修改 应该使用copy,养成好的习惯.
当然用NSString用copy和strong是没有什么区别的
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000 }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000 }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000 }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000 }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Menlo; color: #008400; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Menlo; color: #703daa; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Menlo; color: #000000; background-color: #ffffff; min-height: 22.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Menlo; color: #000000; background-color: #ffffff }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Menlo; color: #d12f1b; background-color: #ffffff }
span.s1 { color: #000000 }
span.s2 { color: #3e1e81 }
span.s3 { color: #d12f1b }
span.s4 { color: #ba2da2 }
span.s5 { color: #4f8187 }