Foundation和CoreFoundation之间的转换

时间:2021-08-30 08:12:38

Foundation是OC的东西,CoreFoundation是C语言的东西

eg:

NSString\NSArray\NSDictionary 属于Foundation

CFStringRef\CFArrayRef\CFDictionaryRef: 属于CoreFoundation

转换时,使用__bridge做桥接。

Foundation----->CoreFoundation

NSString * text = @"23";

CFStringRef str = (__bridge CFStringRef)text;

CoreFoundation -----> Foundation

NSString * str = (__bridge NSString *)KCFStringRef;