Typically, you use copy for security with classes that have mutable options like NSString , NSArray , other collection classes, etc. To understand why, think about what is happening here ...
Once upon a time
@interface MyClass : NSObject @property (retain) NSString *happyString; - (void)rejoice; @end
Then one day
- (void)bigBadMethod { MyClass *myObject = [[[MyClass alloc] init] autorelease]; NSMutableString *theString = [NSMutableString stringWithString:@"I'm happy!"]; myObject.happyString = theString;
when suddenly ...
[theString setString:@"BRAAAAIIINNNSSSSS"]; [myObject rejoice];
And you donβt want this, do you? So use @property (copy) if you don't want to mutate until you look!
source share