核心数据 - 创建 NSFetchedResultsController 时运行时崩溃

Nic*_*ick 2 runtime-error core-data objective-c nsfetchedresultscontroller ios

我使用的 TableViewController 类与您在 Xcode 中启动新的 Master-Detail Application 项目时创建的类非常相似。因此,我使用的是在 TableViewController 类中预先填充的相同代码供我自己使用。但是,我遇到了运行时崩溃,我不知道为什么。我在我的应用程序的另一类中使用了这个确切的代码,它运行良好。

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

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Binder" inManagedObjectContext:[appDelegate managedObjectContext]];
    [fetchRequest setEntity:entity];

    // Edit the sort key as appropriate.
    //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
    //NSArray *sortDescriptors = @[sortDescriptor];

    //[fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".

//This is where it crashes
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[appDelegate managedObjectContext] sectionNameKeyPath:nil cacheName:@"Master"];
//End crash
    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)

我不确定这里要包含哪些其他代码片段。当崩溃发生时,输出没有告诉我任何信息,Xcode 跳转到主线程的这一部分:

libsystem_kernel.dylib`__kill:
0x972893b0:  movl   $786469, %eax
0x972893b5:  calll  0x9728b4c2                ; _sysenter_trap
0x972893ba:  jae    0x972893ca                ; __kill + 26 //This is highlighted
0x972893bc:  calll  0x972893c1                ; __kill + 17
0x972893c1:  popl   %edx
0x972893c2:  movl   27739(%edx), %edx
0x972893c8:  jmpl   *%edx
0x972893ca:  ret    
0x972893cb:  nop  
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?谢谢

Nic*_*ick 5

感谢@flashfabrixx,问题是我没有使用排序描述符,而在使用NSFetchedResultsController. 一旦我重新添加了排序描述符,一切都完美无缺。