xcode 中的几个笔记 (下划线变量)
访问量: 2847
下划线 变量是什么?
refer to: http://stackoverflow.com/a/14117230/445908
xcode 中, 一旦接口中声明了某个变量,就可以在 m 文件中实现它们。 对于变量,我们要为它增加getter/setter. 所以,
// .h 文件: @interface SomeClass : NSObject @property (strong) UIImage *image; @end // .m 文件中 @implementation SomeClass @synthesize image = _image; @end
在上面的 @synthesize image = _image; 就是为了 让xcode(或者oc) 自动生成getter/setter方法, _image 就是为了自动生成代码方便而制定的临时变量。 之所以 对 xx 的 setter/getter 叫 _xx ,(加上个下划线) 就是一种 约定。