Created
November 30, 2012 20:18
-
-
Save wjlafrance/4178315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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