基本的ARC使用规则
2015-11-25 12:28
441 查看
代码中不能使用retain, release, retain, autorelease
不重载dealloc(如果是释放对象内存以外的处理,是可以重载该函数的,但是不能调用[super dealloc])
不能使用NSAllocateObject, NSDeallocateObject
不能在C结构体中使用对象指针
id与void *间的如果cast时需要用特定的方法(__bridge关键字)
不能使用NSAutoReleasePool、而需要@autoreleasepool块
不能使用“new”开始的属性名称 (如果使用会有下面的编译错误”Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”)
----
ARC之@property
1,weak:delegate和IBOutlet用该属性来声明
2,assign:一般数据变量,BOOL
3,unsafe_unretained等价weak。
4,readwrite和readonly-----需要类似@property (nonatomic, strong, readonly) NSString *name;
不重载dealloc(如果是释放对象内存以外的处理,是可以重载该函数的,但是不能调用[super dealloc])
不能使用NSAllocateObject, NSDeallocateObject
不能在C结构体中使用对象指针
id与void *间的如果cast时需要用特定的方法(__bridge关键字)
不能使用NSAutoReleasePool、而需要@autoreleasepool块
不能使用“new”开始的属性名称 (如果使用会有下面的编译错误”Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”)
----
ARC之@property
属性值 | 关键字 | 所有权 |
strong | __strong | 有 |
weak | __weak | 无 |
unsafe_unretained | __unsafe_unretained | 无 |
copy | __strong | 有 |
assign | __unsafe_unretained | 无 |
retain | __strong | 有 |
2,assign:一般数据变量,BOOL
3,unsafe_unretained等价weak。
4,readwrite和readonly-----需要类似@property (nonatomic, strong, readonly) NSString *name;
相关文章推荐
- linux video 编程 h264 YUYV
- 【iOS】关于kvc中的setValuesForKeysWithDictionary为model赋值的一些常见知识
- mysql localhost登录和tcp/ip登录 strace
- http keepalive and tcpkeepalive
- UITableViewCell中的使用cell和cell.contentView的区别
- 一个杀不死的小强,kill进程无效的原因
- OC中使用布尔类型的注意事项
- GCD高级用法:分派源与信号量 7个 Demo
- Codeforces Round #333 (Div. 2)A. Two Bases(模拟,计算进制)
- 简单算法之费式数列
- 225. Implement Stack using Queues
- 图算法:2、计算带有负权值的单源最短路径:Bellman-Ford算法
- 前端2
- 创建通知
- Google protobuf的安装及使用
- jQuery插件之ajaxFileUpload(ajax文件上传)
- 用iPhone4做真机调试时,提示"There was an internal API error"
- oracle 先安装客户端再安装服务端导致的tns无法解析错误--2015.11.25
- 换硬币
- 命令行快捷键