SIGBART on [[NSFetchedResultsController alloc] initWithFetchRequest

Pie*_*ero 1 iphone nsfetchedresultscontroller ios

我在代码中的这一行收到sigbart错误:

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"ViewTwo"];
Run Code Online (Sandbox Code Playgroud)

这是方法:

- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
    return __fetchedResultsController;
}

// Set up the fetched results controller.
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyData" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];

// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"ViewTwo"];

aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return __fetchedResultsController;
}
Run Code Online (Sandbox Code Playgroud)

但这是一个奇怪的错误,因为在控制台中没有给我任何解释,所以我无法理解我做错了什么.

Sco*_*ets 5

NSFetchedResultsController需要排序描述符和托管对象上下文.你没有提供排序描述符,所以你必须给它.