【发布时间】:2013-02-08 21:59:38
【问题描述】:
// .h
@property ( strong, nonatomic ) NSString *note;
// .m
@synthesize note = _note;
- ( id ) initWithNote: ( NSString * )note {
self = [ super init ];
if ( self ) {
_note = note; // _note is just a instance variable.
self.note = note; // 'self.note = note;' is using setter method.
return self;
}
return nil;
}
@property ( strong, nonatomic ) NSString *note; 影响 setter 和 getter 方法。
并且默认情况下,ARC 上的变量是 __strong 类型。
那么_note = note; 和self.note = note; 有什么区别呢?
而不是strong,非ARC 上的retain 在这种情况下会有所作为。
【问题讨论】:
标签: iphone ios properties automatic-ref-counting