CYC- OC中@protected等关键字概述
来源:互联网 发布:设计餐厅菜单软件 编辑:程序博客网 时间:2024/06/05 21:03
关于变量的作用域@protected —Methods defined in the class and any subclasses can directly access the instance variables that follow.This is the default case.该类和所有的子类中的方法可以直接访问这样的变量,这是默认的。@private —Methods defined in the class can directly access the instance variables that follow, but subclasses cannot.该类中的方法可以访问这样的变量,子类不可以。@public —Methods defined in the class and any other classes or modules can di- rectly access the instance variables that follow.除了自己和子类中的方法外,也可以被其他类或者其他模块中的方法所访问。开放性最大。@package —For 64-bit images, the instance variable can be accessed anywhere within the image that implements the class.对于64位图像,这样的成员变量可以在实现这个类的图像中随意访问。全局变量(extern)在程序的开始处,没有在一个方法里面写了int gMoveNumber=0;那么我们说这个变量就是全局变量,也就是说在这个模块中的任何位置可以访问这个变量。这样的变量也是外部全局变量,在其他文件中也可以访问它。但是访问的时候要重新说明下这个变量,说明的方法是:extern int gMoveNumber;当然我们也可以在声明的时候加上extern关键字。extern int gMoveNumber=0;这样的话在其他的类中使用还是需要重新说明一下了,而且这时候编译器会给出警告。如果这个全局变量只是在自己的类中使用,或者其他的类使用的它情况也比较小,那么我们把它定义成第一种情况,如果在外部文件使用的也比较多的话,那么我们把它定义成第二种情况。这种定义其实违背了封装性。静态变量(static)因为全局变量是全局的,影响封装,所以有时候要用静态变量。static int gMoveNumber;这是这个变量是这个类中的静态变量。如果不定义初始值的话为零。如果静态变量定义在方法中,那么这个变量在方法执行完之后还是有效的,如果在第一次调用的时候改变了这个变量的值,那么在第二次调用的时候,这个变量的值是被改变过的值。如果被定义在类中,那么这种改变也是有效的,就是作用域发生了改变。一个在方法中,一个在类中。atomic和nonatomicnonatomic是告诉系统不要使用mutex(互斥)锁定。这种锁定会导致系统的性能低下,所以一般在多线程的时候使用atomic,平时多数用nonatomic。@synthesize和@dynamic@synthesize will generate getter and setter methods for your property.@ synthesize将生成getter和setter方法为你的财产。@dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)@dynamic只是告诉编译器的getter和setter方法实现不是类本身,而是其他地方(如超类)Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet: 用途@dynamic如有NSManagedObject的子类(CoreData)或当你想创建一个插座的属性定义为一个超类没有定义为一个出口:
0 0
- CYC- OC中@protected等关键字概述
- java中public,private,protected等关键字的使用场景。
- OC中assign、copy 、retain等关键字的含义
- OC中assign、copy 、retain等关键字的含义
- oc中关键字super
- OC中public、protected、private 的区别?
- C++中public protected private关键字
- Java中private , public , protected 几个关键字
- protected关键字
- protected关键字
- iOS中关键字概述
- OC-010.OC类中的修饰可见性的关键字@private、@protected、@public
- OC中关键字的意思
- OC中类变量的@protected,@private,@public,@package区别
- OC中类变量的@protected,@private,@public,@package区别
- OC 中 @private @protected @public @package 的含义
- java中public,private,protected,(default)关键字
- Java基础: 关键字 protected
- 维度模型数据仓库(十) —— 快照
- 流式大数据处理的三种框架:Storm,Spark和Samza
- Delphi怎么判断一个文件存在与否,文件还是文件夹?
- openwrt uci的使用
- Swoole-真正的PHP Web开发框架
- CYC- OC中@protected等关键字概述
- LeetCode Add Two Numbers
- sessionstage和localstage的应用实例
- Unity3D-Mecanim动画系统-MatchTarget()目标匹配
- Collection的所有的方法演示
- ICCV 2011 一篇文章:Ensemble of Exemplar-SVMs
- Jquery+Ajax+Json+ashx生成表
- Spark - 大数据Big Data处理框架
- lamda模糊查询