Reputation: 277
I have a plist which looks like this. I usually access using the following lines of code:
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
CGFloat redFloat = (CGFloat)[[plistDict objectForKey:@"red"] floatValue];
However as it is nested - how do I access the colour red in BackgroundColour?
Thanks.
Upvotes: 2
Views: 199
Reputation: 1652
CGFloat redFloat = [[[plistDict objectForKey:@"BackgroundColour"] objectForKey:@"red"] floatValue];
Upvotes: 0
Reputation: 119031
You can use valueForKeyPath:
to shortcut too:
CGFloat redFloat = (CGFloat)[[plistDict valueForKeyPath:@"BackgroundColour.red"] floatValue];
Upvotes: 1
Reputation: 726609
Absolutely: reading plist
into a dictionary gives you a dictionary of dictionaries, so you need to access BackgroundColour
first:
CGFloat redFloat = (CGFloat)[[[plistDict objectForKey:@"BackgroundColour"] objectForKey:@"red"] floatValue];
New syntax lets you write it with fewer characters:
CGFloat redFloat = (CGFloat)[plistDict[@"BackgroundColour"][@"red"] floatValue];
Upvotes: 3