- (id)mutableCopyWithZone:(NSZone *)zone{ HSPerson *person = [[HSPerson allocWithZone:zone] init]; person.age = self.age; person.height = self.height; return person;} |
- (void)setName:(NSString *)name{ _name = [name copy];} |
@property (nonatomic, copy) NSMutableString *name; |
- (void)setName:(NSMutableString *)name{ _name = [name copy];} |
@property (nonatomic, strong) NSString *name; |
NSMutableString *string = [NSMutableString stringWithFormat:@"汉斯哈哈哈"];HSPerson *person = [[HSPerson alloc] init];person.name = string;// 可以改变person.name的值,因为其内部没有生成新的对象[string appendString:@" hans"];NSLog(@"name = %@", person.name); |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |