是“自我”吗?必要? [英] Is "self" necessary?
问题描述
在Objective-C中使用self是否有必要或者只是一个好习惯?我一直都没有使用它而根本没有使用它,我似乎没有注意到任何差别。是不是只是暗示?
Is using "self" ever necessary in Objective-C or maybe just a good practice? I have gone from using it all the time to not using it at all and I don't seem to really notice any difference. Isn't it just implied anyway?
推荐答案
自我
是必要的你希望一个对象发送消息,好吧, self
。通过getter / setter访问属性有时也是有益的,在这种情况下,您还需要使用 self
,如 self.propertyname
或 self.propertyname = value
。 (这些不等于 propertyname
或 propertyname = value
。
self
is necessary if you wish for an object to send messages to, well, itself
. It is also occasionally beneficial to access properties through getters/setters, in which case you'll also need to use self
, as in self.propertyname
or self.propertyname = value
. (These are not equivalent to propertyname
or propertyname = value
.
这篇关于是“自我”吗?必要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!