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