在ARC环境下,编译器是不会处理c语言申请的内存,
在C语言和OC混合开发的时候,C语言指针和oc的指针相互转换的时候,使用桥接.
__bridge__transfer 将coreDatafoundation对象给了foundation,并且移交了对象管理权,不需要release;(foundation中使用coreDatafoundation)/CFBridgingRelease
__bridge 只是将coreDatafoundation对象给了foundation,并没有移交了对象管理权,需要release;
(foundation中使用coreDatafoundation)
__bridge__retained (corefoundation 中使用foundation)
/**
CoreFoundation与Fundation框架的桥接 : 3种方式
1. __bridge : 可以将CF对象转换成了Foiundation对象, 但是没有移交对象的所有权
2. __bridge_transfer / CFBridgingRelease : 可以将CF对象转换成了Foiundation对象, 同时移交对象的所有权
3. __bridge_retained : 可以将Foiundation对象转换成了CF对象. 这种方式使用几率非常低
*/
//方式一: 先转换成CF CF ---> NS CFRelease
// CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
// CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
//
// NSString *firstNameStr = (__bridge NSString *)(firstName);
// NSString *lastNameStr = (__bridge NSString *)(lastName);
//
// NSLog(@"firstNameStr: %@", firstNameStr);
// NSLog(@"lastNameStr: %@",lastNameStr);
//
// //CF框架没有ARC机制
//
// CFRelease(firstName);
// CFRelease(lastName);
// 方式二: 直接转换成NSString
// NSString *firstNameStr = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
// NSString *lastNameStr = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
// 方式三: 直接转换成NSString
NSString *firstNameStr = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastNameStr = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);