NSMakeCollectable

来源:互联网 发布:iphone 解压软件 编辑:程序博客网 时间:2024/06/06 10:05

This function is a wrapper for CFMakeCollectable, but its return type is id—avoiding the need for casting when using Cocoa objects.

This function may be useful when returning Core Foundation objects in code that must support both garbage-collected and non-garbage-collected environments, as illustrated in the following example.

- (CFDateRef)foo {
    CFDateRef aCFDate;
    // ...
    return [NSMakeCollectable(aCFDate) autorelease];
}

CFTypeRef style objects are garbage collected, yet only sometime after the last CFRelease is performed. Particularly for fully-bridged CFTypeRef objects such as CFStrings and collections (such as CFDictionary), you must call either CFMakeCollectable or the more type safe NSMakeCollectable, preferably right upon allocation.