My hobby project is getting over my head! I am using an XML parser, which gives me a set of values
row.blurb
row.url
row.keywords
etc.
I now need to put them into an NSDictionary to populate a table, but my understanding of dictionaries is letting me down. I was expecting to be able to say something like
[exhibitors addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:
[row.blurb],@"blurb",[row.url],@"url",[row.keywords],"keywords",nil]];
But, as none of you will be at all surprised, I get a crash. Can anyone help me with the correct way to do this?
Thanks.
You are providing a
Cstring as one of the keys ->"keywords".That is not a valid key in an
NSDictionaryinstance. You probably intended it to be@"keywords".To add, you are also leaking memory as you are creating an object but aren’t releasing it as you don’t have a reference. You can use the convenience method
dictionaryWithObjectsAndKeys :to create an autoreleased instance so that you don’t leak.