本文介绍了私有@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.

这篇关于私有@property是否创建一个@private实例变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:14