“@private"是什么意思?在Objective-C中是什么意思? [英] What does "@private" mean in Objective-C?
本文介绍了“@private"是什么意思?在Objective-C中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@private
在 Objective-C 中是什么意思?
What does @private
mean in Objective-C?
推荐答案
它是一个可见性修饰符——这意味着声明为 @private
的实例变量只能通过同一类的实例.子类或其他类无法访问私有成员.
It's a visibility modifier—it means that instance variables declared as @private
can only be accessed by instances of the same class. Private members cannot be accessed by subclasses or other classes.
例如:
@interface MyClass : NSObject
{
@private
int someVar; // Can only be accessed by instances of MyClass
@public
int aPublicVar; // Can be accessed by any object
}
@end
另外,澄清一下,Objective-C 中的方法总是公开的.不过,有多种方法可以隐藏"方法声明——参见 这个问题 了解更多信息.
Also, to clarify, methods are always public in Objective-C. There are ways of "hiding" method declarations, though—see this question for more information.
这篇关于“@private"是什么意思?在Objective-C中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文