IOS基础--@private|@protected| @public|@package

来源:互联网 发布:腾讯微信域名检测 编辑:程序博客网 时间:2024/06/06 04:14
注解 说明 @private the instance variable isaccessible only within the class that declares it. 声明的变量只能在内部使用 @protected Theinstance variable is accessible within the class that declares itand within classes that inherit it. All instance variables withoutan explicit scope directive have @protected scope.
实例变量能被声明它的类和子类访问,所有没有显式制定范围的实例变量都是 @public Theinstance variable is accessible everywhere.
实例变量可以在任何地方使用 @package Using themodern runtime, an @package instance variablehas @public scope inside theexecutable image that implements the class, but acts like@private outside.使用modern运行时,一个@package实例变量在实现这个类的可执行文件镜像中实际上是@public的,但是在外面就是@private【runtime需要再看一下苹果文档Runtime Programming Guide】The @package scope for Objective-Cinstance variables is analogous to private_extern for C variables andfunctions. Any code outside the class implementation’s image thattries to use the instance variable gets a link error.Objective-C中的@package与C语言中变量和函数的private_extern类似。任何在实现类的镜像之外的代码想使用这个实例变量都会引发linkerrorThisscope is most useful for instance variables in framework classes,where @private may be too restrictivebut @protected or @public toopermissive.这个类型最常用于框架类的实例变量,使用@private太限制,使用@protected或者@public又太开放
阅读全文
0 0
原创粉丝点击