I started a small Xcode project to investigate whether an NSMutableString
property should be copy
or retain
. I declared my property with the copy
attribute:
@property (nonatomic,copy) NSMutableString *stringA;
Then initialized it as self.stringA = [NSMutableString new];
finally tried to set a string [stringA setString:@"A"];
.
However the program gives,
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with setString:'"
Is it because the resulting string is a NSString
? Does this mean I should declare my NSMutableString
properties using retain
attribute and NSString
properties using copy
?