我正在我的 viewDidLoad
方法中执行此代码
fetchedResultCont = NSFetchedResultsController(fetchRequest: req,
managedObjectContext: container.viewContext,
sectionNameKeyPath: nil,
cacheName: nil)
文档说我们可以使用缓存来加快进程,但没有实现。
谁能告诉我如何使用缓存代替缓存名称中的 nil 来加快进程?
最佳答案
您只需指定一个将用作缓存目录名称的字符串。
fetchedResultCont = NSFetchedResultsController(fetchRequest: req,
managedObjectContext: container.viewContext,
sectionNameKeyPath: "SectionKey",
cacheName: "MyCache")
但是,由于您没有在提取请求中使用部分,因此缓存不会给您带来好处:
The name of the cache file the receiver should use. Pass nil to prevent caching.
Pre-computed section info is cached to a private directory under this name. If Core Data finds a cache stored with this name, it is checked to see if it matches the fetchRequest. If it does, the cache is loaded directly—this avoids the overhead of computing the section and index information. If the cached information doesn’t match the request, the cache is deleted and recomputed when the fetch happens.
关于ios - 如何在Core Data中的NSFetchedResultsController中使用缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56164558/