URL(fileURLWithPath:Bundle.main.path(forResource:“ ports”,ofType:“ geojson”)!)是零吗?

时间:2019-02-22 00:21:58

标签: ios swift mapbox

当我在应用程序中运行该行时,波纹管行返回nil(因此使该应用程序崩溃)。这行代码来自有关分组的地图框example here

npm start

我实现了他们建议添加的以下链接:link 并将其添加到项目中,如下所示: enter image description here

我在做什么错了,我该如何解决?

1 个答案:

答案 0 :(得分:5)

如果是

Bundle.main.path(forResource: "ports", ofType: "geojson")!

破解意味着您需要检查该文件的目标成员身份

用于跟踪

if let file = Bundle.main.path(forResource: "ports", ofType: "geojson") {
     let url = URL(fileURLWithPath:file)
}
else { 
    print("Not exists")
}

因此选择文件并打勾

enter image description here