我有以下代码,我从Core Data堆栈获取fetchedObjects。我如何访问这些元素?它抛出一个错误,说我需要一个IndexPath?
func loadDataToMapView() {
guard let mapCoordinates = fetchedResultsControllerForCoordinateEntity.fetchedObjects else { return 0 }
let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: 1)
print(coordinate2)
答案 0 :(得分:9)
NSFetchedResultsController.object方法需要一个IndexPath。 IndexPath由section和row组成。如果您只是一个部分,可以尝试使用此
let myIndexPath = IndexPath(row: 1, section: 0)
let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: myIndexPath)