ios - 核心数据 - 创建 NSFetchedResultsController 时的运行时崩溃
<p><p>我使用的 TableViewController 类与您在 Xcode 中启动新的 Master-Detail 应用程序项目时创建的类非常相似。因此,我使用在 TableViewController 类中预填充的相同代码供我自己使用。但是,我遇到了运行时崩溃,我不知道为什么。我在我的应用程序的另一类中使用了这个确切的代码,它运行良好。</p>
<pre><code>- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [ init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = ];
;
// Edit the sort key as appropriate.
//NSSortDescriptor *sortDescriptor = [ initWithKey:@"timeStamp" ascending:NO];
//NSArray *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 = [ initWithFetchRequest:fetchRequest managedObjectContext: sectionNameKeyPath:nil cacheName:@"Master"];
//End crash
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (!) {
// 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, );
abort();
}
return _fetchedResultsController;
}
</code></pre>
<p>我不确定这里还包括哪些其他代码片段。崩溃发生时输出没有告诉我任何信息,Xcode 跳转到主线程的这一部分:</p>
<pre><code>libsystem_kernel.dylib`__kill:
0x972893b0:movl $786469, %eax
0x972893b5:calll0x9728b4c2 ; _sysenter_trap
0x972893ba:jae 0x972893ca ; __kill + 26 //This is highlighted
0x972893bc:calll0x972893c1 ; __kill + 17
0x972893c1:popl %edx
0x972893c2:movl 27739(%edx), %edx
0x972893c8:jmpl *%edx
0x972893ca:ret
0x972893cb:nop
</code></pre>
<p>有什么想法吗?
谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>感谢@flashfabrixx,问题是我没有使用排序描述符,而在使用<code>NSFetchedResultsController</code> 时需要它们。一旦我重新添加了排序描述符,一切都运行良好。 </p></p>
<p style="font-size: 20px;">关于ios - 核心数据 - 创建 NSFetchedResultsController 时的运行时崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15711272/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15711272/
</a>
</p>
页:
[1]