这是来自 The Objective-C 2.0 Programming Language 的示例。我只是想知道,在底部的设置器中,我可以使用value = [newValue retain]
而不是value = [newValue copy]
吗?
@interface MyClass : NSObject
{
NSString *value;
}
@property(copy, readwrite) NSString *value;
@end
// assume using garbage collection
@implementation MyClass
@dynamic value;
- (NSString *)value {
return value;
}
- (void)setValue:(NSString *)newValue {
if (newValue != value) {
value = [newValue copy];
}
}
@end