我必须NSFetchedResultsController
在后台线程上执行fetch .
我目前的解决方案结构如下:
dispatch_queue_t fetchQueue = dispatch_queue_create("backgroundfetching", NULL);
dispatch_async(fetchQueue,^{
// 1. Create NSManagedObjectContext
// 2. Create NSFetchRequest
// 3. Create NSFetchedResultsController
// 4. PerformFetch
dispatch_async(dispatch_get_main_queue(),^{
[[self table] reloadData];
});
});
dispatch_release(fetchQueue);
Run Code Online (Sandbox Code Playgroud)
我的第一次测试运行良好,但这是适当的方式吗?
我收到很多关于指定崩溃的崩溃报告但不知道从哪里开始修复它,因为我无法自己重现它并且崩溃报告是匿名发送的.
你会发现它与NSFetchedResultsController
我正在使用的东西有关.
以下是该崩溃报告的摘录.报告之间的唯一区别是索引的范围[...]index (someLargeIndex) beyond bounds (1)[...]
.其余报告中的其余部分保持不变.
Application Specific Information:
*** Terminating app due to uncaught exception \\\'NSRangeException\\\', reason: \\\'*** -[_PFBatchFaultingArray objectAtIndex:]: index (262144) beyond bounds (1)\\\'
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x31d1e00c __kill + 8
1 libsystem_c.dylib 0x32ac4f95 raise + 17
2 AppName 0x0003d961 uncaught_exception_handler (PLCrashReporter.m:137)
3 CoreFoundation 0x349b57d3 __handleUncaughtException + 239
4 libobjc.A.dylib 0x33f9506b _objc_terminate + 103
5 libstdc++.6.dylib 0x3338ae3d __cxxabiv1::__terminate(void (*)()) + 53
6 libstdc++.6.dylib 0x3338ae91 std::terminate() + 17
7 libstdc++.6.dylib 0x3338af61 __cxa_throw …
Run Code Online (Sandbox Code Playgroud)