文档上记录是这样的

The Scope of Instance Variables

Toenforce the ability of an object to hide its data, the compilerlimits the scope of instance variables—that is, limits theirvisibility within the program.

为了强制一个对象隐藏其数据,编译器限制实例变量范围以限制其在程序中的可见性

But toprovide flexibility, it also lets you explicitly set the scope atfour levels. Each level is marked by a compilerdirective:

但是为了提供灵活性,苹果也让开发者显式设置范围(四选一)

Directive

Meaning

@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.

实例变量能被声明它的类和子类访问,所有没有显式制定范围的实例变量都是@protected

@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类似。任何在实现类的镜像之外的代码想使用这个实例变量都会引发linkerror

Thisscope is most useful for instance variables in framework classes,where @private may be too restrictivebut@protected or @public toopermissive.

这个类型最常用于框架类的实例变量,使用@private太限制,使用@protected或者@public又太开放

 
 

iOS中四种实例变量的范围类型@private@protected@public@package的更多相关文章

  1. oc 中四种实例变量的范围类型@private@protected@public@package

    To enforce the ability of an object to hide its data, the compiler limits the scope of instance vari ...

  2. java中四种引用类型(对象的强、软、弱和虚引用)

    对象的强.软.弱和虚引用在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2 ...

  3. IOS的四种数据存储方式及优劣

    IOS有四种经常使用数据存储方式: 第一种方法:用NSUserDefaults存储配置信息 NSUserDefaults被设计用来存储设备和应用的配置信息.它通过一个工厂方法返回默认的.也是最经常使用 ...

  4. Java中四种引用:强、软、弱、虚引用

    这篇文章非常棒:http://alinazh.blog.51cto.com/5459270/1276173 Java中四种引用:强.软.弱.虚引用 1.1.强引用当我们使用new 这个关键字创建对象时 ...

  5. [转]C++中四种类型转换符的总结

    C++中四种类型转换符的总结 一.reinterpret_cast用法:reinpreter_cast<type-id> (expression)    reinterpret_cast操 ...

  6. java中四种引用类型

    java中四种引用类型  今天看代码,里面有一个类java.lang.ref.SoftReference把小弟弄神了,试想一下,接触java已经有3年了哇,连lang包下面的类都不了解,怎么混.后来在 ...

  7. C#中四种常用集合的运用(非常重要)

    C#中4个常用的集合 1.ArrayList ArrayList类似于数组,有人也称它为数组列表.ArrayList可以动态维护,而数组的容量是固定的. 它的索引会根据程序的扩展而重新进行分配和调整. ...

  8. C++中四种类型转换以及const_cast是否能改变常量的问题

    we have four specific casting operators:dynamic_cast, reinterpret_cast, static_cast and const_cast. ...

  9. 转:深入浅出spring IOC中四种依赖注入方式

    转:https://blog.csdn.net/u010800201/article/details/72674420 深入浅出spring IOC中四种依赖注入方式 PS:前三种是我转载的,第四种是 ...

随机推荐

  1. C#中与C++中的 LPWSTR(wchar_t *) 对应的类型

    1.设置 CharSet = CharSet.Unicode [DllImport("test.dll", EntryPoint = "sum()", Char ...

  2. OpenSessionInViewFilter 的配置及作用(原文地址: http://blog.csdn.net/sunsea08/article/details/4545186)

    spring为我们解决hibernate的Session的关闭与开启问题. Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Sessio ...

  3. c++中的类(class)-----笔记(类多态)

    1,多态是一种运行期绑定机制,通过这种机制,实现将函数名绑定到函数具体实现代码的目的.一个函数的名称与其入口地址是紧密相连的,入口地址是该函数在内存中的起始地址.如果对一个函数的绑定发生在运行时刻而非 ...

  4. redis 4 集群重启与数据导入

    1.redis 4 平时启用aof db与每天的完整备份. 2.集群状态检查 cluster info 检查集群状态 cluster nodes 检查节点状态 redis-cli -c -p 7000 ...

  5. LibreOJ 6277. 数列分块入门 1

    题目链接:https://loj.ac/problem/6277 参考博客:https://www.cnblogs.com/stxy-ferryman/p/8547731.html 两个操作,区间增加 ...

  6. 【mybatis基础】mybatis开发dao两种方法

    mybatis是一个支持普通SQL查询,存储过程和高级映射的优秀的持久层的框架,是apache下的顶级项目.mybatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.mybat ...

  7. matlab基础绘图知识

    axis([xmin xmax ymin ymax])   %设置坐标轴的最小最大值 xlabel('string')                             %标记横坐标 ylabe ...

  8. java 操作zookeeper

    java 操作zookeeper(一) 首先要使用java操作zookeeper,zookeeper的javaclient 使我们更轻松的去对zookeeper进行各种操作,我们引入zookeeper ...

  9. SOA与微服务的区别

    乍一看: 1.SOA更抽象. 2. SOA是拆分服务后,用ECS等手段,将服务组合调度. 微服务则是拆分服务后组合成各种业务. https://blog.csdn.net/HeatDeath/arti ...

  10. HDU 6081 度度熊的王国战略(全局最小割堆优化)

    Problem Description度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族.哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士.所以这一场战争,将会十分艰难.为了更好的进攻 ...