iOS中四种实例变量的范围类型@private@protected@public@package
文档上记录是这样的
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的更多相关文章
- oc 中四种实例变量的范围类型@private@protected@public@package
To enforce the ability of an object to hide its data, the compiler limits the scope of instance vari ...
- java中四种引用类型(对象的强、软、弱和虚引用)
对象的强.软.弱和虚引用在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2 ...
- IOS的四种数据存储方式及优劣
IOS有四种经常使用数据存储方式: 第一种方法:用NSUserDefaults存储配置信息 NSUserDefaults被设计用来存储设备和应用的配置信息.它通过一个工厂方法返回默认的.也是最经常使用 ...
- Java中四种引用:强、软、弱、虚引用
这篇文章非常棒:http://alinazh.blog.51cto.com/5459270/1276173 Java中四种引用:强.软.弱.虚引用 1.1.强引用当我们使用new 这个关键字创建对象时 ...
- [转]C++中四种类型转换符的总结
C++中四种类型转换符的总结 一.reinterpret_cast用法:reinpreter_cast<type-id> (expression) reinterpret_cast操 ...
- java中四种引用类型
java中四种引用类型 今天看代码,里面有一个类java.lang.ref.SoftReference把小弟弄神了,试想一下,接触java已经有3年了哇,连lang包下面的类都不了解,怎么混.后来在 ...
- C#中四种常用集合的运用(非常重要)
C#中4个常用的集合 1.ArrayList ArrayList类似于数组,有人也称它为数组列表.ArrayList可以动态维护,而数组的容量是固定的. 它的索引会根据程序的扩展而重新进行分配和调整. ...
- C++中四种类型转换以及const_cast是否能改变常量的问题
we have four specific casting operators:dynamic_cast, reinterpret_cast, static_cast and const_cast. ...
- 转:深入浅出spring IOC中四种依赖注入方式
转:https://blog.csdn.net/u010800201/article/details/72674420 深入浅出spring IOC中四种依赖注入方式 PS:前三种是我转载的,第四种是 ...
随机推荐
- 【scrapy】其他问题2
今天爬取豆瓣电影的是时候,出现了两个问题: 1.数据无法爬取并输出Retrying <GET https://movie.douban.com/robots.txt> 看起来像是被拦截了. ...
- php抓取股票数据
public function stock(){ $curl = new Curl(); $curl->setUserAgent('Mozilla/5.0'); $curl->get('h ...
- NumPy 切片和索引
NumPy 切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样. ndarray 数组可以基于 0 - n 的下标进行索引,切片对象可以 ...
- 最短路 poj1125
输入一个n表示有n个点,接下来n行,每行(假设是u)第一个数字m表示有m对数字(每一对两个数字v,w,表示u到v的时间w),后面接m对数字.找一个起点,它到其他点所花费的时间(求起点到其他点距离的最大 ...
- FZU-1752.(A^B mod C)(快速幂与快速乘优化)
我把自己演哭了... 心酸.jpg 写了很多个版本的,包括数学公式暴力,快速幂TLE等等,最后想到了优化快速幂里的乘法,因为会爆longlong,但是和别人优化的效率简直是千差万别...? 本题大意: ...
- mybatis知识点(已掌握)
1.${} 和 #{} 的区别? ${} 直接显示传入数据,不能防止sql注入,一般用于传数据库对象(比如表名). #{} 传入数据被当成字符串,自动加上双引号,防止sql注入. 2.有哪些Execu ...
- vue-app项目,将px自动转化为rem
1. 安装lib-flexible: npm install --save lib-flexible 2.安装postcss-loader和postcss-px2rem: npm install -- ...
- java中钩子方法的概念
钩子方法源于设计模式中模板方法(Template Method)模式,模板方法模式的概念为:在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新 ...
- Android 工程目录
app java:我们写Java代码的地方,业务功能都在这里实现 res:存放我们各种资源文件的地方,有图片,字符串,动画,音频等,还有各种形式的XML文件 Gradle Scripts 1.res资 ...
- 地图调起URI API(通过连接直接调用百度地图)
网站:http://lbsyun.baidu.com/index.php?title=uri/api/web 地图调起URI API 百度地图URI API是为开发者提供直接调起百度地图产品(百度We ...