我正在以编程方式创建一个直接指向文档目录的 plist 文件。这是我的代码..
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myList.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"myList.plist"] ];
}
NSMutableArray *data ;
if ([fileManager fileExistsAtPath: path])
{
data = [[NSMutableArray alloc] initWithContentsOfFile: path];
}
else
{
// If the file doesn’t exist, create an empty dictionary
data = [[NSMutableArray alloc] init];
}
data = [[NSMutableArray alloc] initWithCapacity:5];
[data addObject:value1];
[data addObject:value2];
[data addObject:value3];
它使用这种格式创建 plist 文件..
<array>
<string>1</string>
<string>2</string>
<string>3</string>
</array>
现在,我想向它添加另一个索引,例如,
<array>
<string>1</string>
<string>2</string>
<string>3</string>
</array>
<array>
<string>11</string>
<string>22</string>
<string>33</string>
</array>
如何以编程方式在我的 plist 文件中添加索引?
任何帮助或建议将不胜感激!
谢谢