Adding keys to Nested NSDictionary
I am having problems creating new keys for a Nested NSDictionary. Here's
what I have done
I have this kind of NSMutableDictionary
NSMutableDictionary *Ga=[NSMutableDictionary
dictionaryWithDictionary:@{@"Node1" :@{@"SubNode11"
:@40,@"SubNode12":@30}}];
Which NSLogs as:
Node1 = {
SubNode11 = 40;
SubNode12 = 30;
};
Now to add another root key and a nested key I did this,
[Ga setObject:@{@"SubNode21" : @555} forKey:@"Node2"];
Now the NSLog outputs:
Node1 = {
SubNode11 = 40;
SubNode12 = 30;
};
Node2 = {
SubNode21 = 555;
};
}
I need to add another key to an existing Node, say SubNode22=345; for
Node2 in a separate line of code, so I thought this might work
[[Ga objectForKey:@"Node2"] setObject:@5555 forKey:@"SubNode22"];
But this show Error "Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSDictionaryI
setObject:forKey:]: unrecognized selector sent to instance"
I don't what the Problem is,, this method seems straight forward to me..
Any solution please.
No comments:
Post a Comment