Why we use ‘copy’ attribute for NSString property?

@interface AClass:NSObjet
@property (nonatomic, copy) NSString* aStrProperty;

Like the code above, we use ‘copy’ instead of ‘retain’ attribute in the NSString property. For the reason, is that we do not want the original NSString object to be modified in this class.

But for that a NSString cannot be modified, why not using the ‘retain’ instead of ‘copy’? Because, one can also assign the aStrProperty with a NSMutableString instead of NSString. Thus, ‘copy’ is more safe than ‘retain’.


电子邮件地址不会被公开。 必填项已用*标注