Understand __Bridge
来源:互联网 发布:wind数据库账号 编辑:程序博客网 时间:2024/06/05 13:30
I didn't understand the __bridge properly for a long time so that i took some hours to read documentation.
from documentation,I know what's the duty of the core key__bridge.
Ok.
Duty: Convert Objective-c type into CoreFoundation type and reconvert.
There are three methods to do this:
Get from Documentation:
__bridge
transfers a pointer between Objective-C and Core Foundation with no transfer of ownership.(weak references)__bridge_retained
orCFBridgingRetain
casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to you.You are responsible for calling
CFRelease
or a related function to relinquish ownership of the object.(strong references, you have to call CFRelease to relinquish memory Because the ownership transfer to yourself)__bridge_transfer
orCFBridgingRelease
moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC.ARC is responsible for relinquishing ownership of the object.(Reconvert to objective-c and take the ownership to ARC)
Example from documentation:
NSLocale *gbNSLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
CFLocaleRef gbCFLocale = (__bridge CFLocaleRef)gbNSLocale;
CFStringRef cfIdentifier = CFLocaleGetIdentifier(gbCFLocale);
NSLog(@"cfIdentifier: %@", (__bridge NSString *)cfIdentifier);
// Logs: "cfIdentifier: en_GB"
CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
NSLocale *myNSLocale = (NSLocale *)CFBridgingRelease(myCFLocale);
NSString *nsIdentifier = [myNSLocale localeIdentifier];
CFShow((CFStringRef)[@"nsIdentifier: " stringByAppendingString:nsIdentifier]);
// Logs identifier for current locale
- Understand __Bridge
- __bridge
- __bridge
- __bridge
- __bridge
- __bridge使用
- Understand inline
- Serialization: Understand
- understand学习
- Understand Zend_Controller_Action
- understand - 笔记
- STL --- understand
- __bridge,__bridge_transfer和__bridge_retained
- __bridge,__bridge_transfer和__bridge_retained
- expected expression __bridge
- void * & __bridge & unsafe_unretained
- __bridge,__bridge_transfer和__bridge_retained
- __bridge关键字用法
- 利用linux mutt 发送邮件(在Shell脚本中使用比较方便)
- Android Looper和Handler
- Linux驱动结构学习笔记 pci之pci_dev
- 网络协议软件
- 外观模式 C++实现
- Understand __Bridge
- myeclipse svn插件subclipse使用http代理同步svn时出现异常
- Jackson 框架,轻易转换JSON
- Ubuntu解压缩zip,tar,tar.gz,tar.bz2
- C++ 构造函数 冒号
- 邮件发送:java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream错误如何解决
- 计算机网络的拓扑结构
- 线程
- landing page的重要性