Reputation: 11861
I have this line of code here:
punchList = [[[NSMutableDictionary alloc]initWithDictionary:[[[areaData GetPunchListDataArray:communityDesc] objectForKey:@"Root"] objectForKey:@"KeyValue"]] autorelease];
but this gives me an error when I run it:
dictionary argument is not an NSDictionary
when I do this:
punchList = [[[NSMutableDictionary alloc]initWithDictionary:[[areaData GetPunchListDataArray:communityDesc] objectForKey:@"Root"]] autorelease];
punchList = [punchList objectForKey:@"KeyValue"];
I get no error and punchList gets populated, how come its not working the first way I did it.
Upvotes: 1
Views: 1362
Reputation: 3130
It may be clearer if you break the code down into separate statements with separate variables. The failing example can be broken out as:
punchListDataArray = [areaData GetPunchListDataArray:communityDesc];
rootObject = [punchListDataArray objectForKey:@"Root"];
// This is not dictionary, so next line fails
possibleDictionary = [rootObject objectForKey:@"KeyValue"];
punchList = [[[NSMutableDictionary alloc]initWithDictionary:possibleDictionary] autorelease];
The second set of statements can be broken down as:
punchListDataArray = [areaData GetPunchListDataArray:communityDesc];
rootObject = [punchListDataArray objectForKey:@"Root"];
// A different variable is being used to initialize
punchList = [[[NSMutableDictionary alloc]initWithDictionary:rootObject] autorelease];
punchList = [punchList objectForKey:@"KeyValue"];
Upvotes: 2
Reputation: 318804
Just because the line punchList = [punchList objectForKey:@"KeyValue"];
doesn't give you an error doesn't mean that the result is correct.
Try this:
punchList = [[[NSMutableDictionary alloc]initWithDictionary:[[areaData GetPunchListDataArray:communityDesc] objectForKey:@"Root"]] autorelease];
punchList = [punchList objectForKey:@"KeyValue"];
NSLog(@"punchList is now a %@", [punchList class]);
id someValue = [punchList objectoForKey:@"SomeKey"];
Running that code should crash with a message about an unknown selector objectForKey:
on some class. And the console will show the log message telling you what punchList
really is at that point.
The reason is the same reason your first block of code fails. And that is because the result of:
[[[areaData GetPunchListDataArray:communityDesc] objectForKey:@"Root"] objectForKey:@"KeyValue"]
is not an NSDictionary
.
Upvotes: 1