第45月第8天 CFBridgingRetain __bridge_retained
1.
如果只想单纯的转换,不涉及变量持有关系,可以这样
id obj = [[NSObject alloc] init];
void *p = (__bridge void*)obj;
id o = (__bridge id)p;
这样void*和id类型就能够互相转换。
_bridge转换中还有两种转换,__bridge_transfer和__bridge_retained
__bridge_retained转换可使要转换赋值的变量也持有所赋值的对象
id obj = [[NSObject alloc] init];
void *p = (__bridge_retained void*)obj;
上面这段代码相当于ARC无效时的
id obj = [[NSObject alloc] init];
void *p = obj;
[(id)p retain];
__bridge_transfer提供与此相反的动作,被转换的变量所持有的对象在该变量被赋值给转换目标变量后随之释放
//p为void*类型
id obj = (__bridge_transfer id)p;
ARC无效时,表述如下
/* ARC无效 */
id obj = (id)p;
[obj retain];
[(id)p release];
https://blog.csdn.net/shengpeng3344/article/details/100740141