再续 Xcode 4.2 中的Automatic Reference Counting (ARC)
来源:互联网 发布:网络安全意识培训内容 编辑:程序博客网 时间:2024/05/01 09:37
上一篇转载文章中,提到了id--void*类型不能隐形转换,需要显性调用.但是文章中都没有说怎么显性转换.
一下午找了N多文档,试验了N多次.找到了正确的调用,可是就是编译不过去,刚刚在apple Developper Forums中看到了类似情况.才知道是xcode4.2的版本没有跟上.造成的某些宏找不到,编译报错.
现在说下ARC开启时,id和void*显性转换.
id objc_unretainedObject(CFTypeRef cf); (void * ==> id,无需单独release)
id objc_retainedObject(CFTypeRef cf); (void * ==> id,需单独release,或使用__weak,如不释放可能造成leak)
CFTypeRef objc_unretainedPointer(id obj); (id ==> void *,CFTypeRef只是obj的一个引用.)
ARC开启时,coreFoundation Type和Foundation类显性转换.(也就是cf type和ns类的转换)
在没有开启ARC时,可以进行强制转换.
在这里引入了3个宏,和__strong,__weak用法一样的(用时放的位置).
__bridge,__bridge_retain,__bridge_transfer,这主要是cf和ns转换用.
__bridge,ARC没有进行retain操作
__bridge_retain,ARC进行retain操作
__bridge_transfer,ARC在操作结束后,进行release操作.类似__weak吧.
看文档说不建议用后2个..容易搞的混淆了..
id my_id;
CFStringRef my_cfref;
NSString *a = (__bridge NSString*)my_cfref;
CFStringRef b = (__bridge CFStringRef)my_id;
英文好的自己看下苹果官方文档
这是一个概括了解ARC的网站
LLVM关于ARC的介绍.个人感觉比apple的有用,详细
苹果官方文档pdf版(附件是pdf的,但是论坛有格式限制.就改成gif的了,图片另存为再改名就好了)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- 再续 Xcode 4.2 中的Automatic Reference Counting (ARC)
- Xcode 4.2 中的Automatic Reference Counting (ARC)转
- 了解Xcode 4.2中Automatic Reference Counting(ARC)
- Swift中的ARC(Automatic Reference Counting)
- Automatic Reference Counting (ARC)
- Automatic Reference Counting (ARC)
- ARC (Automatic Reference Counting)
- 杂项设备和字符设备的区别
- linux 拾遗
- 由Kindle展现出的Android发展之路
- 28个HTML5小说明
- html5的预载入技术
- 再续 Xcode 4.2 中的Automatic Reference Counting (ARC)
- html特殊符编码
- .net打包/C#WinFrom程序打包/图解.net打包/.net安装部署图解/VS2008项目的安装与部署图解
- 当程序员的你
- html5 input各种type
- 设计模式之对象的创建
- C#关闭程序询问是否退出
- php常见中文乱码的解决
- bash shell数组模拟队列queue和shell数组使用技巧