この構造を持つ.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) にテキストを挿入/置換するにはどうすればよいですか?