将 2 个 NSArray 数据保存到 NSDocumentDirectory 中的 2 个文件

Save 2 NSArray data to 2 files in NSDocumentDirectory

我需要将 2 个数组中的数据保存到文档中,第一个已保存,但第二个没有!

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];


    NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

    NSString *rangePath = [documentsDir stringByAppendingPathComponent:@"Range.plist"];
    NSString *indexPath = [documentsDir stringByAppendingPathComponent:@"Select.plist"];

    [finalMutable writeToFile:rangePath atomically:YES];
    [finalIndex writeToFile:indexPath atomically:YES];

}

更新:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [finalIndex addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]];
}

您无法保存第二个文件,因为 finalIndex 数组包含 NSIndexPath objects.NSIndexPath 对象无法存储在 plist 文件中。 plist 支持的数据类型有: 大批, 字典, 细绳, 数字, 数据, 日期, 布尔值