Objective-C综合属性名称覆盖 [英] Objective-C synthesize property name overriding
问题描述
我试图通过属性名称覆盖来理解synthesize
指令的目的.假设我有一个定义如下的接口:
I am trying to understand the purpose of the synthesize
directive with property name overriding. Say that I have an interface defined as follow:
@interface Dummy ... {
UILabel *_dummyLabel;
}
@property (retain, nonatomic) UILabel *dummyLabel;
在实现文件中,我有:
@synthesize dummyLabel = _dummyLabel;
据我了解,"dummyLabel"只是实例变量"_dummyLabel"的别名. self._dummyLabel和self.dummyLabel之间有什么区别吗?
From what i understand, "dummyLabel" is just an alias of the instance variable "_dummyLabel". Is there any difference between self._dummyLabel and self.dummyLabel?
推荐答案
是. self._dummyLabel
未定义,但是_dummyLabel
未定义.
Yes. self._dummyLabel
is undefined, however _dummyLabel
is not.
点语法扩展为简单的方法调用,因此它不是特定于属性的.如果您有一个名为-(id)someObject
的方法,例如在object.someObject
的情况下,就好像您编写了[object someObject];
.
Dot syntax expands out to simple method invocations, so it's not specific to properties. If you have a method called -(id)someObject
, for example in the case of object.someObject
, it will be as if you wrote [object someObject];
.
self.dummyLabel //works
self._dummyLabel //does not work
dummyLabel //does not work
_dummyLabel //works
[self dummyLabel]; //works
[self _dummyLabel]; //does not work
这篇关于Objective-C综合属性名称覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!