我有一个.plist
具有这种结构的文件,
我想添加或替换第 5 项。我正在使用此代码
NSError *error ;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Introduction.plist"];
NSMutableArray *data = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSString *comment = str;
[data replaceObjectAtIndex:1 withObject:comment];
[data writeToFile:path atomically:YES];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:path]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Introduction" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath:path error:&error];
}
如果我改变replaceObjectAtIndex:
它5
会改变我的 plist 结构,我不希望这样。
如何在特定索引的第 5 行(第 5 项)插入/替换文本?