
There are a number of data types in the Core Foundation framework and the Foundation framework that can be used interchangeably. This capability,called toll-free brIDging,means that you can use the same data type as the parameter to a Core Foundation function call or as the receiver of an Objective-C message. For example, NSLocale (see NSLocale Class Reference) is interchangeable with its Core Foundation counterpart,CFLocale (see CFLocale Reference). Therefore,in a method where you see an NSLocale * parameter,you can pass a CFLocaleRef,and in a function where you see a CFLocaleRef parameter,you can pass an NSLocale instance. You cast one type to the other to suppress compiler warnings,as illustrated in the following example.
NSLocale *gbNSLocale = [[NSLocale alloc] initWithLocaleIDentifIEr:@"en_GB"]; |
Note from the example that the memory management functions and methods are also interchangeable—you can use CFRelease with a Cocoa object and release and autorelease with a Core Foundation object.
Note: When using garbage collection,there are important differences to how memory management works for Cocoa objects and Core Foundation objects. See “Using Core Foundation with Garbage Collection” for details.
Toll-free brIDging has been available since Mac OS X v10.0. table 13-1 provIDes a List of the data types that are interchangeable between Core Foundation and Foundation. For each pair,the table also Lists the version of Mac OS X in which toll-free brIDging between them became available.
| Core Foundation type | Foundation class | Availability | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| | NSArray | Mac OS X v10.0 | ||||||||||||||||||||||||||||||
| CFAttributedStringRef | NSAttributedString | Mac OS X v10.4 | ||||||||||||||||||||||||||||||
| CFCalendarRef | NSCalendar | CFCharacterSetRef | NSCharacterSet | CFDataRef | NSData | CFDateRef | NSDate | CFDictionaryRef | NSDictionary | CFErrorRef | NSError | Mac OS X v10.5 | ||||||||||||||||||||
| CFLocaleRef | NSLocale | CFMutableArrayRef | NSMutableArray | CFMutableAttributedStringRef | NSMutableAttributedString | CFMutableCharacterSetRef | NSMutableCharacterSet | CFMutableDataRef | NSMutableData | cfmutabledictionaryRef | NSMutableDictionary | CFMutableSetRef | NSMutableSet | CFMutableStringRef | NSMutableString | CFNumberRef | NSNumber | CFReadStreamRef | NSinputStream | CFRunLoopTimerRef | NSTimer | CFSetRef | NSSet | CFStringRef | Nsstring | CFTimeZoneRef | NSTimeZone | CFURLRef | NSURL | CFWriteStreamRef | NSOutputStream | Mac OS X v10.0 |
NSDateFormatter is not toll-free brIDged to CFDateFormatter. (#add莫非桥接的均以Ref结尾)
总结以上是内存溢出为你收集整理的Toll-Free Bridging全部内容,希望文章能够帮你解决Toll-Free Bridging所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)