A primary characteristic of Core Foundation objects is that they're based on an opaque (or private) type; it is thus difficult to inspect the internal data of an object directly. Base Services, however, provide two functions with which you can inspect Core Foundation objects. These functions return descriptions of an object and of the object's type.
To find out the contents of a Core Foundation object, call the
CFCopyDescription
function on that object and then print the character sequence "contained" in the referred-to string object:
Listing 2 Using CFCopyDescription
void describe255(CFTypeRef tested) { char buffer[256]; SInt32 got; CFStringRef description = CFCopyDescription(tested); CFStringGetBytes(description, CFRangeMake(0, CFStringGetLength(description)), CFStringGetSystemEncoding(), '?', TRUE, buffer, 255, &got); buffer[got]=(char)0; fprintf(stdout, "%s", buffer); CFRelease(description); }
This example shows just one approach for printing a description. You could use CFString functions other than
CFStringGetBytes
to get the actual string.
To determine the type of an "unknown" object, obtain its type ID with the
CFGetTypeID
function and compare that value with known type IDs until you find a match. You obtain an object's type ID with the
CFGetTypeID
function. Each opaque type also defines a function of the form
CF
Type
GetTypeID
(for example,
CFArrayGetTypeID
); this function returns the type ID for that type.
To display information about the type of a Core Foundation object in the debugger, use the
CFGetTypeID
function to get its type ID, then pass that value to the
CFCopyTypeIDDescription
function:
/* aCFObject is any Core Foundation object */ CFStringRef descrip = CFCopyTypeIDDescription(CFGetTypeID(aCFObject));
Note: String Services include two functions, both declared in |
ImportantTheCFCopyDescription
and theCFCopyTypeIDDescription
functions are for debugging only. Because the information in the descriptions and their format are subject to change, do not create dependencies on them in your code.