获取财产清单的最佳方法是什么?
1 - 来自主要捆绑,即:
NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"];
2 - 或从Documents目录获取路径,即:
// Data.plist code - get path from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our plist file.
NSString *plistPath = [documentsPath
stringByAppendingPathComponent:@"Data.plist"];
// check to see if Data.plist exists in documents
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
// if not in documents, get property list from main bundle
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
什么和为什么? 如果两者都是正确的那么为什么我们不使用只有一行代码的第一个呢?
答案 0 :(得分:2)
简单规则: