OC中的@property、@synthesize和@dynamic的用法
来源:互联网 发布:域名301重定向新网 编辑:程序博客网 时间:2024/06/01 10:24
1.@property
声明property的语法为:@property (参数1,参数2) 类型 名字;
如:@property(nonatomic, strong) UIView *view;
其中参数主要分为三类:
读写属性: (readwrite/readonly)
setter语意:(assign/retain/strong/weak/copy)
原子性: (atomic/nonatomic)
各参数意义如下:
readwrite: 产生setter\getter方法
readonly: 只产生简单的getter,没有setter。
assign: 默认类型,setter方法直接赋值,而不进行retain操作
retain: setter方法对参数进行release旧值,再retain新值。
copy: setter方法进行Copy操作,与retain一样
nonatomic: 禁止多线程,变量保护,提高性能
atomic:可使用多线程,安全性不高
2.@synthesizeobj=_obj;
为成员变量_obj起个属性名称叫obj。是为了区分成员变量_obj和属性名称obj,在.m里面使用的时候见到_obj就知道是成员变量了,见到self.obj就知道是属性了。
@synthesize 指令可以告诉编译器在编译期间产生getter/setter方法。
3.@dynamic
@dynamic指令,自己实现方法。有些存取是在运行时动态创建的,如在CoreData的NSManagedObject类使用的某些。如果你想这些情况下,声明和使用属性,但要避免缺少方法在编译时的警告,可以使用@dynamic动态指令。例如
@interface Demo : NSManagedObject {
}
@property (retain) NSString*text;
@end
@implementation Demo
@dynamic text;
@end
0 0
- OC中的@property、@synthesize和@dynamic的用法
- OC中@property和@synthesize的用法
- OC基础-@property,@synthesize和@dynamic 16
- 第二章、Objective-C中的@property、@synthesize和dynamic的用法(iOS学习笔记,从零开始)
- 黑马程序员 --- OC中@property和@synthesize的用法
- 在OC中,property、synthesize和点语法的用法
- OC学习之@property和@synthesize用法
- OC学习: @property和@synthesize用法概述
- OC中的@property、@synthesize和id
- @property中的@synthesize/@dynamic 区别
- OC学习@property和@synthesize的使用
- ios-基础用法之【3】-@property、@synthesize和dynamic的用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- ceph ( requests are blocked ) 异常解决方法
- jenkins changelog中文乱码问题解决方法
- Windows Server 2008 R2 服务器安装Orecle10G步骤
- Solr安装与配置
- 附录_Android中常用英文单词
- OC中的@property、@synthesize和@dynamic的用法
- 辣妈帮电脑版下载 v7.0.1 pc版
- 图像二值化
- linux下mongodb常用命令记录
- 附录_HTTP状态码
- AsyncQueryHandler的使用
- C++ std::pair<>
- Ext.js 古怪的问题(表单布局崩溃)
- ContactsUI(简介)