NSFetchRequest返回的获取的对象不在正确的部分中

时间:2018-12-01 22:22:50

标签: ios swift core-data

无论我在sectionNameKeyPath: "value"中输入什么值,获取的对象都会按照它们在数据库中保存的顺序返回。部分的数目是正确的,但是无论我按部分fetchedResultsController.sections还是fetchedResultsController.object(at: indexPath)查看获取的对象,我都得到相同的结果。

这是在UITableViewController中

lazy var fetchedResultsController: NSFetchedResultsController<Dice> = {
    let fetchRequest: NSFetchRequest<Dice> = Dice.fetchRequest()

    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "createdAt", ascending: false)]

    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let context = appDelegate.persistentContainer.viewContext

    // Doesn't matter what I set in the "sectionNameKeyPath" value
    let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: "set.identifier", cacheName: nil)

    fetchedResultsController.delegate = self

    return fetchedResultsController
}()

还有其他人看到过吗?

0 个答案:

没有答案