如何在iOS上作为NSDictionary从磁盘加载plist文件? [英] How do I load a plist file from disk as a NSDictionary on iOS?
本文介绍了如何在iOS上作为NSDictionary从磁盘加载plist文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从磁盘(文档,应用程序缓存,...)加载来自资源包的plist文件。
I want to load the plist file from disk (documents, application cache, ...) not from a resource bundle.
推荐答案
您可以使用 - initWithContentsOfFile:或+dictionaryWithContentsOfFile:
从文件加载plist,如果文件不存在则创建该文件:
Load a plist from a file, and create the file if it did not exist:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
self.plistFile = [[paths objectAtIndex:0]
stringByAppendingPathComponent:@"example.plist"];
self.plist = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFile];
if (!plist) {
self.plist = [NSMutableDictionary new];
[plist writeToFile:plistFile atomically:YES];
}
这篇关于如何在iOS上作为NSDictionary从磁盘加载plist文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文