NSFetchedResultsController调用时候crash

来源:互联网 发布:姜卫鹏中超数据分析 编辑:程序博客网 时间:2024/06/08 01:16

crash信息如下:

persistent cache of section information does not match the current configuration.  You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:

2016-12-06 10:29:25.906 CoredataSample[1781:67800] CoreData: error: fetch request = <NSFetchRequest: 0x7b156fc0> (entity: Employee; predicate: ((null));

原因:说得很清楚了,在调用的时候没有清除之前的cache信息所导致的。

解决方式:

1. 不进行缓存

_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"number" cacheName:@"Root"];

修改为

  _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"number" cacheName:nil];

2. 可以进行缓存,但是在缓存新的之前先把旧有的删除掉

[NSFetchedResultsController deleteCacheWithName:@"Root"];
    _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"number" cacheName:@"Root"];


0 0
原创粉丝点击