是“自我”吗?必要? [英] Is "self" necessary?

查看:121
本文介绍了是“自我”吗?必要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

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