私有@property是否创建一个@private实例变量?

问题描述:

我已阅读 将自动为@property 创建相应的实例变量,并且默认情况下,ivars为@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.