无论我在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
}()
还有其他人看到过吗?