Read binary plist into NSDictionary

醉酒当歌 提交于 2019-12-18 07:04:45

问题


Is there simple way to parse the binary plist file into the NSDictionary representation? I am searching something like that:

NSString* strings = [NSString stringWithContentsOfURL: ... encoding: NSUnicodeStringEncoding error: ...];
NSMutableDictionary* pairs = (NSMutableDictionary*)[strings propertyListFromStringsFileFormat];

Using this code caused the exception while parsing the binary plist file.


回答1:


Are you looking for [NSDictionary dictionaryWithContentsOfFile:]?




回答2:


Considering a file called DataStorageFile.plist, you can use:

NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"DataStorageFile" ofType:@"plist"];
self.data = [NSDictionary dictionaryWithContentsOfFile:dataPath];

If you want an array:

self.data = [NSArray arrayWithContentsOfFile:dataPath];


来源:https://stackoverflow.com/questions/6622037/read-binary-plist-into-nsdictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!