OC中retain,copy和assign的setter和getter方法的写法和区别

用retain修饰 setter 方法:

- (void)setName:(NSString *)name { 
    if (_name != name) { 
       [_name release]; 
      _ name = [name retain];
    } 
}

用copy修饰 setter方法:

- (void)setName:(NSString *)name { 
    if (_name != name) { 
       [_name release]; 
      _ name = [name copy];
    } 
}

用assign修饰 setter方法:

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

    _name = name;

}

getter方法均是

- (NSString *)name{

      return  _name;
}

你可能感兴趣的:(OC中retain,copy和assign的setter和getter方法的写法和区别)