写一个 setter 方法用于完成 @property (nonatomic, retain) NSString *name

写一个 setter 方法用于完成 @property (nonatomic, copy) NSString *name

答:

// retain

- (void)setName:(NSString *)str {

[str retain];

[_name release];

_name = str;

}

// copy

- (void)setName:(NSString *)str {

id t = [str copy];

[_name release];

_name = t;

}

05-04 05:13