什么是“@ private”平均值在Objective-C? [英] What does "@private" mean in Objective-C?

查看:143
本文介绍了什么是“@ private”平均值在Objective-C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@private 是什么意思在Objective-C?

What does @private mean in Objective-C?

推荐答案

它是一个可见性修饰符 -it意味着声明为 @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屋!

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