i have a really simple plist which is loaded into a NSDictionary. However, when i try to access a specific value, no data is available.
This is how my plist is structured:
edit* xml got messed up. You can tak开发者_开发技巧e a look at it at pastebin: http://pastebin.com/C419ZVeJ
Here i load the plist:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [bundlePath stringByAppendingPathComponent:@"Test.plist"];
NSDictionary *metaPlistData = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSDictionary *meta = [metaPlistData valueForKey:@"meta"];
NSDictionary *assets = [meta valueForKey:@"sd"];
(i have removed the line where i access the key=1 entry)
When i inspect the "meta" dictionary and the "assets" dictionary in gdb, "meta" contains the required entries. However, assets always is nil. I am really lost here.. any ideas why? I load data from plists using this approach at other locations in my code and it has never been a problem.
On first blush, it looks like you're off by one layer in the hierarchy. "sd" isn't a key in the "meta" dictionary, it's a key in the "1" dictionary. Try this:
NSDictionary *meta = [metaPlistData objectForKey:@"meta"];
NSDictionary *one = [meta objectForKey:@"1"];
NSDictionary *assets = [one objectForKey:@"sd"];
Note too that you should be using -objectForKey:
for dictionary access (-valueForKey:
will probably work in this context but it belongs to the key-value coding mechanism which is something a little different.)
(Also, not sure if this is just a paste issue, but your plist looks incomplete.)
精彩评论