我正在創建一個應用程序,允許您記錄棋盤遊戲。我將日誌存儲在plist中,並試圖找出如何追加plist。我想我理解這個邏輯,但是我很難將它放入代碼中。將一些數據附加到plist
我的plist看起來像這樣:
現在我想是這樣的,但我相信它會直接覆蓋,而不是附加
//get path for root directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSLog(@"paths: %@",paths);
//get path for documents directory
NSString *documentsPath = [paths objectAtIndex:0];
NSLog(@"documentsPath: %@",documentsPath);
//get the path for logs.plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"logs.plist"];
//create dictionary with values
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:myLogTitle, name, players, myNotes, nil] forKeys:[NSArray arrayWithObjects:@"Log Title",@"Name",@"Players","Notes", nil]];
//write out data
[plistDict writeToFile:plistPath atomically:YES];
任何幫助的plist文件會非常感激。
http://stackoverflow.com/questions/4779877/how-to-write-in -append-mode-for-text-file – Balu 2013-05-13 04:16:24
要允許在對象中進行修改,您必須將數據存儲在可變對象中,例如'NSMutableArray','NSMutableDictionary'等等,而不是'NSArray'或'NSDictionary'。我希望它足夠清晰 – 2013-05-13 05:20:38