问题是,如果我使用并发上下文创建NSFetchedResultController,它将在并发线程上工作吗?
如果没有,我应该怎么做才能在后台线程中从CoreData获取数据?我应该没有工作吗 NSFetchedResultController?并使用一些异步提取请求?还是performBlocks?
var context: NSManagedObjectContext
init() {
context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
context.persistentStoreCoordinator = persistentContainer.persistentStoreCoordinator
}
让fetchRequest = NSFetchRequest(entityName:实体名称)
let sortDescriptor = NSSortDescriptor(key: sortDescriptorKey, ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
let controller = NSFetchedResultsController(fetchRequest: fetchRequest,
managedObjectContext: context,
sectionNameKeyPath: nil,
cacheName: nil)