原文地址
For attributes whose type is an immutable value class that conformsto theNSCopyingprotocol,you almost always should specifycopyinyour@propertydeclaration.Specifyingretainissomething you almost never want in such a situation.
Here's why you want to do that:
NSMutableString *someName = [NSMutableString stringWithString:@"Chris"];
Person *p = [[[Person alloc] init] autorelease];
p.name = someName;
[someName setString:@"Debajit"];
The current value of thePerson.namepropertywill be different depending on whether the property isdeclaredretainorcopy—it will be@"Debajit"ifthe property is markedretain,but@"Chris"ifthe property is markedcopy.
Since in almost all cases you want topreventmutatingan object's attributes behind its back, you should mark theproperties representing themcopy.(And if you write the setter yourself instead of using@synthesizeyoushould remember to actually usecopyinsteadofretaininit.)
爱华网

