Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created November 30, 2012 20:18
Show Gist options
  • Save wjlafrance/4178315 to your computer and use it in GitHub Desktop.
Save wjlafrance/4178315 to your computer and use it in GitHub Desktop.
#import <CoreFoundation/CoreFoundation.h>
void DescribeCFObject(CFTypeRef cfobject)
{
CFStringRef description = CFCopyDescription(cfobject);
printf("%s\n", CFStringGetCStringPtr(description, CFStringGetSystemEncoding()));
CFRelease(description);
}
const void *RetainCFObjectForCFArray(CFAllocatorRef allocator, const void *object)
{
return (void *) CFRetain((CFTypeRef) object);
}
void ReleaseCFObjectForCFArray(CFAllocatorRef allocator, const void *object)
{
CFRelease((CFTypeRef) object);
}
CFStringRef DescribeCFObjectForCFArray(const void *object)
{
return CFCopyDescription((CFTypeRef) object);
}
int main(int argCount, const char **argValues)
{
CFArrayCallBacks callbacks;
callbacks.version = 0;
callbacks.retain = &RetainCFObjectForCFArray;
callbacks.release = &ReleaseCFObjectForCFArray;
callbacks.copyDescription = &DescribeCFObjectForCFArray;
CFMutableArrayRef myArray = CFArrayCreateMutable(kCFAllocatorDefault, argCount, &callbacks);
for (int index = 0; index < argCount; index++) {
CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, argValues[index], CFStringGetSystemEncoding());
CFArraySetValueAtIndex(myArray, index, string);
CFRelease(string);
}
DescribeCFObject(myArray);
CFRelease(myArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment