私有@property 是否创建了@private 实例变量? [英] Does a private @property create an @private instance variable?

查看:23
本文介绍了私有@property 是否创建了@private 实例变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过 @synthesize 会自动为 @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 的支持变量已经隐藏,@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 实例变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆