Obj-C @synthesize [英] Obj-C @synthesize

查看:107
本文介绍了Obj-C @synthesize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在Objective C中使用下划线前缀属性名称

iPhone App Developer初学者:

iPhone App Developer Beginner here:

in .h

@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;

in .m

@synthesize detailDescriptionLabel = _detailDescriptionLabel;

我习惯看到

@synthesize detailDescriptionLabel;

= _ 让我失望,这是做什么的?

the = _ is throwing me off, what is this doing?

推荐答案

每个属性都有一个实例变量支持。该语言允许以不同的方式命名它们。通过 @synthesize detailDescriptionLabel = _detailDescriptionLabel; ,您基本上是说使用 _detailDescriptionLabel 作为后备实例变量property detailDescriptionLabel 。如果您只是执行 @synthesize detailDescriptionLabel; ,它会隐含地理解实例变量具有相同的名称。

Each property is backed by an instance variable. The language allows for them to be named differently. By doing @synthesize detailDescriptionLabel = _detailDescriptionLabel;, you're basically saying that use _detailDescriptionLabel as the backing instance variable for the property detailDescriptionLabel. If you just do @synthesize detailDescriptionLabel;, it implicitly understands that the instance variable has the same name.

这篇关于Obj-C @synthesize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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