sorting - 核心数据 : Background fetch, NSFetchedResultsController 和排序时间

标签 sorting core-data background nsfetchedresultscontroller

我遇到的问题如下:

我有一个 UITableView我从 NSFetchedResultsController 提供数据它从核心数据中检索大约 6000 行。 fetchBatchSizeNSFetchRequest设置为 20,如果我不应用任何 NSSortDescriptor获取速度足够快,不会阻塞 UI 线程。

但是,我确实需要显示按字母顺序排序的那些行,我使用以下 NSSortDescriptor:

[[[NSSortDescriptor alloc] initWithKey:@"optionText" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];

这是当事情发生变化时,提取操作现在需要大约 3 秒才能完成,因为 6000 行正在被排序。显然,在那几秒钟内,UI 被阻塞,用户体验很糟糕。

我知道我可以在后台线程中进行提取,然后将对象 ID 传递给主线程,但在这种情况下,我如何仍然使用 NSFetchedResultsController在主线程中(我也用它来观察数据的变化)?

我也有indexed我正在排序的属性,但只优化查找而不是排序性能。

任何想法将不胜感激,谢谢!

最佳答案

如何使用 NSFetchRequest 的 batchSize属性(property)?

If you set a non-zero batch size, the collection of objects returned when the fetch is executed is broken into batches. When the fetch is executed, the entire request is evaluated and the identities of all matching objects recorded, but no more than batchSize objects’ data will be fetched from the persistent store at a time. The array returned from executing the request will be a proxy object that transparently faults batches on demand. (In database terms, this is an in-memory cursor.)

关于sorting - 核心数据 : Background fetch, NSFetchedResultsController 和排序时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5661301/

相关文章:

css - Susy 网格中部分的全尺寸背景

html - 表格的 CSS 表格背景颜色未在 Chrome 中显示

algorithm - 您如何找到最佳的堆栈移动集,以对*已知*列表进行排序?

ios - Swift CoreData 到 UICollectionView

algorithm - 哈希排序与快速排序的比较

ios - 将数据异步加载到表格 View 单元格中的正确方法/可接受的标准是什么?

iPhone4 : Application loses all data saved in CoreData on click home button

ios - 核心剧情: grid lines background color

java - 算法类(class): Output of int sort and method to sort Strings

c - 在c中对数组进行排序