Documents ディレクトリに .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
ですか?