标签:__bridge objective-c对象与core f
Core Foundation 对象主要使用在用C语言编写的Core Foundation 框架中,并引用计数的对象.与Objective-C对象区别很少.无论哪种框架生成的对象,一旦生成,便可在两种框架中使用.这种转换不需要额外的CPU资源,因而也被称为”免费桥”.
/****************************(1)***********************/
/*
CFTypeRef CFBridgingRetain(id X){
return (__bridge_retained CFTypeRef)X;
}
id CFBridgingRelease(CFTypeRef X){
return (__bridge_transfer id)X;
}
*/
CFMutableArrayRef cfObject = NULL;
{
id obj = [[NSMutableArray alloc] init];
cfObject = CFBridgingRetain(obj);
//也可使用 cfObject = (__bridge_retained CFMutableArrayRef)obj;
/*
ARC机制在 Core Foundation框架是否有效?
输出打印如下:
retain count = 2
retain count = 1
由此可知ARC机制在Core Foundation下并不起作用
*/
CFShow(cfObject);
printf("retain count = %ld\n",CFGetRetainCount(cfObject));
}
printf("retain count = %ld\n",CFGetRetainCount(cfObject));
CFRelease(cfObject);
/****************************(2)***********************/
//使用__bridge转换来替代CFBridgingRetain或__bridge_retained转换
/*
cfObject = (__bridge CFMutableArrayRef)obj;
但使用__bridge并不改变对象的持有情况.
*/
版权声明:本文为博主原创文章,未经博主允许不得转载。
Objective-C对象与Core Foundation对象
标签:__bridge objective-c对象与core f
原文地址:http://blog.csdn.net/judy_luo/article/details/47035295