简体   繁体   English

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

[英]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.

相关问题 Bundle.main.path(forResource:ofType:inDirectory:) 返回 nil - Bundle.main.path(forResource:ofType:inDirectory:) returns nil Bundle.main.path(forResource :)返回nil - Bundle.main.path(forResource:) returns nil 当目录和文件名正确时,Bundle.main.path(forResource:ofType:inDirectory :)返回nil - Bundle.main.path(forResource:ofType:inDirectory:) returns nil when directory and filename are correct 当应用名称包含“空格”时,Bundle.main.path(forResource:ofType:inDirectory :)返回nil - Bundle.main.path(forResource:ofType:inDirectory:) returns nil when app name contains “space” 为什么Bundle.main.path(forResource:fileName,ofType:“ txt”)总是返回nil? - why does Bundle.main.path(forResource: fileName, ofType: “txt”) always return nil? 当使用 UIImage(named:“”) 和 Bundle.main.path(forResource:) 合成图像时,为什么性能会有很大差异? - When use UIImage(named:“”) and Bundle.main.path(forResource:) compositing images, why is the performance very different? Bundle.main.url(forResource:“ hello”,withExtension:“ html”)返回nil - Bundle.main.url(forResource: “hello”, withExtension: “html”) is returning nil Bundle.main.url(forResource: "AppleIncRootCertificate", withExtension: "cer") == nil - Bundle.main.url(forResource: "AppleIncRootCertificate", withExtension: "cer") == nil 在应用程序启动时读取 Bundle.main.path 是否耗时? - Reading Bundle.main.path at the launching of the app is time consuming or not? 斯威夫特3:db.execute不能与获取路径一起使用Bundle.main.path - Swift 3 : db.execute not run with get path use Bundle.main.path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM