You do not need to wrap it with anything. Just add it to id and add to array. You can do this for any type of CoreFoundation derived from CFType (nothing that ends in "Ref" is free).
Alternatively, you can include NSMutableArray * in CFMutableArrayRef and call CFArrayAppendValue (). This is no longer characteristic; it calls the save / release callbacks specified when creating the array. (An exceptional exception exception is [NSDictionary setValue: forKey:], which copies keys, while the corresponding CFDictionary function does not. It is sometimes useful to have a dictionary with the key of a "mutable" object (for example, NSURLConnection, with -far data as values), you safe if you do not violate the requirement that the hash does not change.)
CoreFoundation types are OO type types that can be used in "simple" C. Using some clever magic (Apple can do this because they write both temporary CF and ObjC environments), instances of types like NSString, NSArray, and NSDictionary (default) "really" instances of CFString, CFArray and CFDictionary. CF types belong to a hierarchy of types whose root is CFType ; notable methods are CFRetain, CFRelease, CFEqual, CFHash and CFCopyDescription. They freely correspond to -retain, -release, -isEqual :, -hash and -description (except that -description is additionally auto-implemented and they have different NULL / nil processing). Apple calls this “free bridging” or “interchangeable data types” (IDT article is no longer in the Mac Dev Center). Ridiculousfish has a nice article called "Bridge" .
This means that, for the most part, you can treat CF types as if they were Objective-C objects. Apple did not make this particularly obvious, but in addition to all the references to the “free bridge”, there are some things that suggest that they are interchangeable.
- NSMakeCollectable () accepts CFTypeRef and returns id (and allows garbage collection, which is not related to iOS, but very important for Mac OS 10.5 +).
- Stuff like
@property (nonatomic, retain) __attribute__((NSObject)) ABAddressBookRef foo; which effectively means "send it -retain and -release, as if it were an instance of Objective-C." - The CALayer.contents property is of type
id , but the only registered thing that it supports is CGImageRef (it also supports CABackingStore, which is -drawRect: draws).
Additional interesting things you can do include defining CFAutorelease .
tc.
source share