0
ドキュメントディレクトリに.plistファイルが存在するかどうかを確認します。 が存在しない場合は、が作成され、それを作成して1番目のエントリにシードします。 がある場合はがあります。私はそれを読んでエントリを追加したいと思います。ファイルを意味条件付きで.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
のファイルを作成する方法は?
(
appDelegate.dictFaves
と仮定すると、有効なNSDictionary
です)*'直接辞書が有効でない場合、その辞書( 'dictFaves')には何が含まれていますか? –@Vince - キャストコメントのthx。 dictFavesには、NSStringオブジェクトと組み合わされた整数キーが含まれています。 – Bassman