2017-04-11 46 views
0

我有以下代碼,我從Core Data棧獲取fetchedObjects。我如何訪問這些元素?它會拋出一個錯誤,說我需要一個IndexPath?無法將Int類型的值轉換爲期望的參數類型IndexPath(Core Data)?

func loadDataToMapView() { 
    guard let mapCoordinates = fetchedResultsControllerForCoordinateEntity.fetchedObjects else { return 0 } 

    let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: 1) 

    print(coordinate2) 

回答

1

NSFetchedResultsController.object方法需要一個IndexPath。 IndexPath由段和行組成。如果你只有一個部分,你可以試試這個

let myIndexPath = IndexPath(row: 1, section: 0) 
let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: myIndexPath) 
+0

得到它的感謝! – konyv12

相關問題