I have a mutlidimensional NSDictionary, and am having problems adding an array to it. My dictionary structure looks like this: (taken by NSLogging the dictionary)
{
Downloaded = {
017315 = "2013-01-16 11:26:33 +0000";
};
Projects = (
{
Docs = { };
"Last Downloaded" = "2013-01-16 10:16:05 +0000";
"Project Name" = "Baring Australia Fund";
}
);
}
I am trying to add a new array to the “Docs” dictionary. The code I am using is
[[[[myDict objectForKey:@"Projects"] objectAtIndex:0] objectForKey:@"Docs"] setObject:[NSMutableArray array] forKey:@"test"];
This is failing with the following error
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7592df0’
If I try to add a Dictionary to the Docs key instead of an array using the code below, it works.
[[[[myDict objectForKey:@"Projects"] objectAtIndex:0] objectForKey:@"Docs"] setObject:[NSMutableDictionary dictionary] forKey:@"test"];
In addition, I am also able to add the new array to the first “Projects” array item, just not to the Docs object within it.
What am I doing wrong, and why is this not working?
Thanks
[[[myDict objectForKey:@"Projects"] objectAtIndex:0] objectForKey:@"Docs"]this is returning you an array.And you are using setObject:forKey: in this array.
[someArray setObject: forKey:]is what your compiler see and throwing error.EDIT:
I checked your code, it is fine. and the above error is coming from some other places.
I mimic-ed your code and it works fine. Have a look, what i tested: