我想用多个数组和数组创建plist文件作为Root类型。我可以在字典中添加多个数组但是我想以编程方式在一个数组中添加所有数组。如何以编程方式创建plist文件并编写数组数据进入它。请指导我并给出一些示例链接。谢谢。 这是我在字典中添加数组的代码:
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Demo.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Demo" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
firstArray = [[NSMutableArray alloc] initWithObjects:@"15-5-123",@"15-5-12",nil];
secondArray = [[NSMutableArray alloc] initWithObjects:@"TestFiling",@"TestFiling",nil];
thirdArray = [[NSMutableArray alloc] initWithObjects:@"15132561",@"15135601", nil];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:firstArray forKey:@"firstArray"];
[dictionary setObject:secondArray forKey:@"secondArray"];
[dictionary setObject:thirdArray forKey:@"thirdArray"];
[dictionary writeToFile:path atomically:NO];
NSDictionary *dictionary1;
dictionary1 = [NSDictionary dictionaryWithContentsOfFile:path];
NSLog(@"dictionary1 %@",dictionary1);
这段代码适用于字典,但我想在数组中添加数组。
答案 0 :(得分:0)
您的代码的第一部分很好,您只需要将第二部分切换为使用数组:
Sum of All Values/ Number