Objective C 初学者语法观察
当你 @synthesize
类似 buttonPressed
,你需要这样做:
@synthesize buttonPressed = buttonPressed_;
我一直在关注一些教程,并且这个问题不断出现。为什么?
Possible Duplicate:
What does @synthesize window=_window do?
How come when you @synthesize
something like buttonPressed
, You need to do this:
@synthesize buttonPressed = buttonPressed_;
I've been following some tutorials and this keeps coming up. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必这样做。
默认情况下,如果您的合成访问器应与实例变量具有相同的名称,则
@synthesize variableName
确实有效。在您的示例中,实例变量称为
buttonPressed_
但您的访问器方法将省略_
,因此仅称为setButtonPressed
和buttonPressed
。You do not have to do it that way.
By default,
@synthesize variableName
does work, if your synthesized accessors shall have the same name as your instance variable.In your example, the instance variable is called
buttonPressed_
but your accessor methods will omit the_
and thus just be calledsetButtonPressed
andbuttonPressed
.