[英]URL(fileURLWithPath: Bundle.main.path(forResource: “ports”, ofType: “geojson”)!) is nil?
The bellow line returns nil when I run the line in the app (thus making the app crash). 当我在应用程序中运行该行时,波纹管行返回nil(因此使该应用程序崩溃)。 This line of code comes from mapboxes example here on grouping.
这行代码来自此处分组的mapboxes 示例 。
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "ports", ofType: "geojson")!)
I implemented that this link which they recommend adding: link And add it to the project as follows: 我实现了他们建议添加的该链接: link并将其添加到项目中,如下所示:
What am I doing wrong and how can I fix this? 我在做什么错,我该如何解决?
If this 如果这
Bundle.main.path(forResource: "ports", ofType: "geojson")!
crashes this means you need to check target membership of this file 崩溃,这意味着您需要检查此文件的目标成员身份
for tracking 用于跟踪
if let file = Bundle.main.path(forResource: "ports", ofType: "geojson") {
let url = URL(fileURLWithPath:file)
}
else {
print("Not exists")
}
so select the file and tick 所以选择文件并打勾
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.