Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

djRA

macrumors newbie
Original poster
Nov 30, 2009
4
0
Is there an equivalent API for CFDictionary to display its contents the way [NSDictionary description] does?

I was able to dump the CFDictionary using XML by:
CFDataRef tempData = CFPropertyListCreateXMLData(NULL, dict);
CFStringRef tempStrRef = CFStringCreateFromExternalRepresentation(NULL, tempData, kCFStringEncodingASCII);

And tempStrRef gets a plist format of the dictionary but [NSDictionary description] has a different output.

Is there a way to get the same behavior as [description] without having to cast CFDictionary to NSDictionary? I can't use Objective-C code in the program.
 
I'm sorry I forgot to mention but I've already tried CFCopyDescription. It has a different output format even less readable than CFStringCreateFromExternalRepresentation due to the extra hash information and the output has no indention unlike CFStringCreateFromExternalRepresentation and [description].

We can't use Objective-C because we're compiling this code as C (*.c). Why as C, you might ask. We're trying to keep it as simple and sort of low-level-ish.

Is it possible to invoke [NSDictionary/NSObject description] in C syntax? Like objc_msgsend() or something like that? :D
 
You could create a separate .h/.m file with a function that calls [dict description] and return it as a CFStringRef.

Why do you need this in the first place? It shouldn't really be used anywhere else but for debugging purposes, according to the docs since the format could change.
 
It sounds to me like you should just write a C function that iterates through the key/value pairs in a CFDictionary and builds a CFString with the exact format you want. Then you don't have to rely on all of this silliness.

-Lee
 
We can't use Objective-C because we're compiling this code as C (*.c). Why as C, you might ask. We're trying to keep it as simple and sort of low-level-ish.

Complicating things to keep them simple seems a bit nonsensical. Just rename to .m and use -description.

Is it possible to invoke [NSDictionary/NSObject description] in C syntax? Like objc_msgsend() or something like that? :D

This is just using ObjC in a more complicated way. You're not fooling the compiler :p
 
We can't use Objective-C because we're compiling this code as C (*.c). Why as C, you might ask. We're trying to keep it as simple and sort of low-level-ish.

Is it possible to invoke [NSDictionary/NSObject description] in C syntax? Like objc_msgsend() or something like that? :D

Nothing like deception to really complicate things.

Isolate the function that returns the description. Implement it in .m or .c or whatever. The function declaration stays the same:
Code:
extern CFStringRef dictDescription( CFDictionaryRef dict );


Why does the string have to be exactly in the -description format? Is it for debugging? Pfah, do whatever works. Is it for exporting to a particular format? Write your own function, like Lee1210 suggested (because -description's output can change, and has in the past). Is the string for something else? What?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.