什么时候在实例变量前加下划线? [英] When do you make an underscore in front of an instance variable?
本文介绍了什么时候在实例变量前加下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
cocoa Objective-c 类中变量前面的下划线是如何工作的?
我在 Apple 的 UIPickerView.h 中看到过这个:
I've seen this at Apple, inside UIPickerView.h:
id<UIPickerViewDataSource> _dataSource;
为什么会有下划线?它有什么特殊的意义吗?一个我必须知道的约定?
why's that underscore there? Does it have a special meaning? A Convention I must know about?
推荐答案
很多人将其用于私有变量,以区分对象内的私有变量和公共变量.
A lot of people use this for private variables, to differentiate between private variables and public variables within an object.
这是一种完全可选的工作方式.
It is a completely optional way of working.
这篇关于什么时候在实例变量前加下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文