CoreData:错误:API滥用:在NSFetchedResultsController中使用SectionNameKeyPath时出错

时间:2018-04-27 21:13:23

标签: swift core-data ios10

在iOS10中,当我尝试传入SectionNameKeyPath时,当我使用NSFetchedResultsController调用performFetch()时出现此错误:

  

CoreData:错误:API滥用:尝试在非拥有协调器上序列化商店访问

以下是一些相关代码:

    let sectionName = NSSortDescriptor(key: "testClass", ascending: true)
let number = NSSortDescriptor(key: "ordinal", ascending: true)
let inventoryName = NSSortDescriptor(key: "name", ascending: false)
fetchRequest.sortDescriptors = [sectionName, number, inventoryName]

if let srcName = sources.fetchedObjects?[0].srcName { //TODO: this is good for 1 source, multiple sources will require an external "source" variable.
    let predicate = NSPredicate(format: "%@ == %K", srcName, "mySource.srcName")
    fetchRequest.predicate = predicate
}

let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.moc, sectionNameKeyPath: "testClass", cacheName: "Root")
aFetchedResultsController.delegate = self
_options = aFetchedResultsController

do {
    try _options!.performFetch()
} catch {
    let nserror = error as NSError
    fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}

fetch仍在运行,但我得到了一堆上面的错误,我相信它最终会导致应用程序崩溃。如果我为SectionNameKeyPath传入nil,则不会发生错误(但是,当然,我需要结果中的部分用于分段的tableview)。 “TestClass”是coredata中的String,是我正在获取的实体的属性。知道会发生什么吗?

0 个答案:

没有答案