_var和self.var之间的区别 [英] difference between _var and self.var

查看:112
本文介绍了_var和self.var之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着所有这些新的ARC内容(不属于NDA ...)的出现,似乎处理属性的默认设置是在实现文件中显式设置没有和ivar的属性,直到您将其与类似的内容进行合成:

With all this new ARC stuff (which does not fall under NDA…) coming out, it seems like the default for dealing with properties is to set the property without and ivar in the implementation file explicitly until you synthesize it with something like:

@synthesize var = _var;

设置变量的最佳实践是什么?我知道varself.var之间的区别是self.var使用点表示法,并且使用var的setter方法.

What's the best practice to use in setting the variable? I know the difference between var and self.var is that self.var is using dot notation and is using the var's setter method.

_var是否等同于在头文件中对其进行设置,就像在往年一样?这种用下划线开头的做法从何而来?

Is _var just the equivalent of setting it up within the header files like in the good ol' days? Where did that practice of prefacing everything with an underscore come from?

推荐答案

_var只是实例变量的另一个名称(大概是这样,当您打算使用访问器时,您不会意外地直接访问它).除了是有效的ivar名称外,它在语言中没有任何特殊含义.

_var is just a different name for the instance variable (presumably so you don't accidentally access directly it when you meant to use an accessor). It doesn't have any special meaning in the language beyond just being a valid ivar name.

这篇关于_var和self.var之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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