views:

254

answers:

1

I am parsing a data file and adding the key-value read from the file into an NSMutableDictionary.

I have noticed that when I print out the content of the dictionary in the debugger, i.e: po myDictionary

some entries have quotes around them and some don't. Why is this?

For instance I see:

{
  "file_path"      = "../dat.txt"
  another_path     = "aa.dat"
  yet_another_path = bb.txt
}

I am using the following line to extract the key and value from the file, after parsing the data down to only the essential bytes

key_str = [[NSString alloc] initWithBytes:[data bytes]
                                   length:total_bytes
                                 encoding:NSUTF8StringEncoding];

val_str is parsed the same way.

Thank you

+1  A: 

You should not use the output of the -debugDescription or -description methods for the purposes of data archival. The format is an implementation detail and subject to change.

I would suggest that you look to NSPropertyListSerialization (and related) to solve your archival needs. It offers an XML format, if you need something akin to human readability.

bbum
Thanks for the replies sofar.I am using gdb 6.3.50-20050815 on a Mac.The problem is the quotes actually end up as part of the key. So, in the posted example: po [myDictionary objectForKey:@"file_path"]this fails because "file_path" has quotes around them in the dictionary. I don't know how the quotes got there. That's what I'd like to figure out and get rid of.
Sebastian
I can't say it enough: **Do not use -debugDescription or -description to generate your keys.** Those methods are not designed for any purpose other than as a debugging tool
bbum
I don't think I communicated clearly the first time. So I am not generating my keys from the debugger; I'm reading them from a data file that contains "variable name"-"value" pair. I am only displaying the debug output as extra information for the purpose of this discussion.So, the "key_str" here is what I parsed out of a data file.
Sebastian