我如何更新 Objective-C 中有很多组项目的 plist 文件?

How can i update plist file which has many group item in Objective-C?

我有一个这样的 plist 文件,现在我想编辑该行。

例如,我想编辑项目 1 中的第 "ZFILMSEAT" 行。

请有人建议我如何更新 plist 文件中的数据。

首先,当您检索 .plist 文件时,将其存储为 NSMutableDictionary

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"your plist name" ofType:@"plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSMutableArray *filmsPlaying = [[NSMutableArray alloc] iniWithArray:[dict objectForKey:@"FilmsPlaying"]];
NSMutableDictionary *filmToEdit = [filmsPlaying objectAtIndex:1];// IRL run a loop to get your desired film
NSString *newSeats = @"1-2-9";
[filmToEdit setObject:newSeats forKey:@"ZFILMSEAT"];
[filmsPlaying replaceObjectAtIndex:1 withObject:filmsToEdit];
[dict setObject:filmsPlaying forKey:@"FilmsPlaying"];

这里有您要编​​辑的影片。对该词典进行编辑后,您需要将其写回 App 的文档目录。 (注意: 你不能将它保存回你的主包,但你可以将它写到文档中)。

NSString *pathForPlist = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
pathForPlist = [savingPath stringByAppendingPathComponent:@"your plist name.plist"];
[dict writeToFile:savingPath automically:YES];

要在主包中编辑它而无需任何编程,您只需在任何文本编辑器或 xcode 本身中打开它并制作您的版本。没什么技术含量。