我正在尝试设置一个基本NSFetchedResultsController
的,它从下面的错误中向我抛出一个“null”错误。由于错误及其 userInfo 都为 null,我不知道我什至可以开始做些什么来找出问题所在。这是那些“让你的头撞到砖墙上却不被告知原因”的编程时刻之一。这是导致崩溃的部分,位于viewDidLoad
:
NSError *error;
if (![_fetchedResultsController performFetch: &error]) {
NSLog(@"Error! %@, %@", error, [error userInfo]);
abort();
}
这是设置控制器的方法:
- (NSFetchedResultsController *) fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName: @"Quote" inManagedObjectContext: [self managedObjectContext]];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending: YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchBatchSize: 50];
NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest managedObjectContext: [self managedObjectContext] sectionNameKeyPath: nil cacheName: @"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
我究竟做错了什么?