Obj-C @synthesize [英] 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屋!