xcode 无法将 Int 类型的值转换为预期的参数类型 IndexPath(核心数据)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43347232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot convert value of type Int to expected argument type IndexPath (Core Data)?
提问by konyv12
I have the following code where I get fetchedObjects from a Core Data stack. How can I access the elements of these? It throws an error saying I need an IndexPath?
我有以下代码,我从核心数据堆栈中获取 fetchedObjects。如何访问这些元素?它抛出一个错误,说我需要一个 IndexPath?
func loadDataToMapView() {
guard let mapCoordinates = fetchedResultsControllerForCoordinateEntity.fetchedObjects else { return 0 }
let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: 1)
print(coordinate2)
回答by Manuel
NSFetchedResultsController.object
method required an IndexPath
. An IndexPath
is composed by section and row. If you have only one section you can try with this
NSFetchedResultsController.object
方法需要一个IndexPath
. AnIndexPath
由段和行组成。如果你只有一个部分,你可以试试这个
let myIndexPath = IndexPath(row: 1, section: 0)
let coordinate2 = fetchedResultsControllerForCoordinateEntity.object(at: myIndexPath)