私有@property是否创建一个@private实例变量?
我已阅读 @property
@protected
.但是,如果我使用类扩展名(如下所示)指示@property
方法是私有的怎么办?
I've read that @synthesize
will automatically create corresponding instance variables for @property
and that ivars are @protected
by default. But, what if I use a class extension (like below) to indicate that the @property
methods are to be private?
// Photo.m
@interface Photo ()
@property (nonatomic, retain) NSMutableData *urlData;
@end
对应的ivar会是@private
吗?还是应该像这样将其明确声明为@private
?
Will the corresponding ivar then be @private
? Or should I explicitly declare it as @private
like so?
// Photo.h
@interface Photo : Resource {
@private
NSMutableData *urlData;
}
@private
实例变量是仅编译时功能.鉴于@property
的后缀ivars已经被隐藏,@private
不会执行任何操作.因此,从本质上讲,它已经是@private
.
@private
instance variables are a compile-time-only feature. Given that the backing ivars for @property
's are already hidden, @private
doesn't do anything. So in essence, it's already @private
.