我正在创建一个应用程序,允许您记录棋盘游戏。我将日志存储在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