我有一个3个数组,我试图在一个视图中保存为3个不同的plist,然后将该数据加载到另一个视图中的数组中。我无法弄清楚如何在我的其他视图中访问plist中的数据并在初始视图中正确保存它。这是我第一次看到的代码。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentsDirectory1 = [documentPaths objectAtIndex:1];
NSString *documentsDirectory2 = [documentPaths objectAtIndex:2];
NSString *documentsDirectory3 = [documentPaths objectAtIndex:3];
NSString *documentPlistPath1 = [documentsDirectory stringByAppendingPathComponent:@"balance.plist"];
NSString *documentsPlistPath2 = [documentsDirectory1 stringByAppendingPathComponent:@"principal.plist"];
NSString *documentsPlistPath3 = [documentsDirectory2 stringByAppendingPathComponent:@"interest.plist"];
NSString *documentsPlistpath4 = [documentsDirectory3 stringByAppendingPathComponent:@"dates.plist"];
[dateValues writeToFile:documentsPlistpath4 atomically:YES];
[balanceLabels writeToFile:documentPlistPath1 atomically:YES];
[pricipalLabels writeToFile:documentsPlistPath2 atomically:YES];
非常感谢任何帮助!
谢谢!
答案 0 :(得分:0)
创建一个数组
NSArray *array = @[@"abc", @"cba"];
获取plist文件的路径
NSString *documentsFolderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fileName = @"my_plist_file";
NSString *filePath = [documentsFolderPath stringByAppendingPathComponent:fileName];
将数组保存到.plist
[array writeToFile:filePath atomically:YES];
从.plist
读取数组NSArray *arrayFromDisk = [NSArray arrayWithContentsOfFile:filePath];