为什么在添加if statements
到后会产生缓存错误NSPredicate
?在我尝试根据 UITABLEVIEW 的标题过滤结果后出现错误。
我收到以下错误:
CoreData: FATAL ERROR: The 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
我查看了其他类似的错误,但无法将它们与我的代码相关联。
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"ExcerciseInfo" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"details.muscle" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
// Sort Results
if ([self.title isEqual: @"Abdominals"]) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"details.muscle == %@", @"Back"];
[fetchRequest setPredicate:predicate];
}
else if ([self.title isEqual: @"Arms"]) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"details.muscle == %@", @"Biceps"];
[fetchRequest setPredicate:predicate ];
}
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:managedObjectContext sectionNameKeyPath:nil
cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}