0
我想检查文档目录中是否存在.plist文件。如果它的确存在而不是,我想创建它并将其与第一个条目一起播种。如果它是否存在我想阅读并附加条目。有条件地创建/读取.plist文件
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
// read Faves file...
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithContentsOfFile:path];
appDelegate.dictFaves = tempDict;
} else {
NSLog(@"Creating Favorites file");
BOOL result = [[NSFileManager defaultManager] createFileAtPath: path contents: (NSData *)appDelegate.dictFaves attributes: nil];
}
// .... and Append it to the list of existing favorites
[appDelegate.dictFaves setObject:newFave forKey:key];
createFileAtPath
表示文件的回报FALSE
没有被创建。- 我质疑铸造
appDelegate.dictFaves
到(NSDATA *)
的有效性。如果这是不明智的,我如何创建一个Dictionary
的文件?所以-[NSDictionary writeToURL:atomically:]
,你可以说:
铸造'NSData的*'直接字典是无效的,该字典('dictFaves')包含什么? – 2012-02-17 09:12:25
@Vince - thx用于投射评论。 dictFaves包含与NSString对象配对的整数键。 – Bassman 2012-02-17 15:31:24