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

时间:2017-07-15 08:42:05

标签: ios 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]];
}

1 个答案:

答案 0 :(得分:1)

您无法保存第二个文件,因为finalIndex数组包含NSIndexPath对象.NSIndexPath对象不能存储在plist文件中。 plist支持的数据类型有: 阵列, 字典, 串, 数, 数据, 日期, 布尔