简体   繁体   English

Bundle.main.path(forResource :)返回nil

[英]Bundle.main.path(forResource:) returns nil

For reasons unknown to me I cannot locate file: 由于我未知的原因,我无法找到文件:

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: ".zip")

It's strange, because when I list all files present in resources directory, it is there. 这很奇怪,因为当我列出资源目录中存在的所有文件时,它就在那里。 I can find other files, but not this one. 我可以找到其他文件,但找不到此文件。 I've also tried different configurations of searching, like: 我还尝试了不同的搜索配置,例如:

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: nil)
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: "")

but with no success. 但没有成功。

EDIT: The following fails as well: 编辑:以下也失败:

Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")

EDIT2: I verify if it's present there by checking what is my resources folder and checking its contents: EDIT2:我通过检查我的资源文件夹并检查其内容来验证它是否存在:

Bundle.main.resourcePath
FileManager.default.contentsOfDirectory(atPath: myResourcesFolder)

在此处输入图片说明

Also I've checked in finder it's actually there. 另外,我已经在finder中检查了它是否确实存在。

It is included in copy Bundle Resources: 它包含在副本捆绑资源中:

在此处输入图片说明

Thanks to https://stackoverflow.com/users/1187415/martin-r : The file system on iOS devices is case-sensitive: "zip" != "ZIP". 感谢https://stackoverflow.com/users/1187415/martin-r:iOS设备上的文件系统区分大小写:“ zip”!=“ ZIP”。 After changing to ZIP it worked perfectly. 更改为ZIP后,它可以完美运行。

First thing is check if you have copied this ZIP file into a bundle at the time adding by looking into Copy Bundle Resource . 首先是通过查看“ Copy Bundle Resource来检查是否在添加时将该ZIP文件复制到Copy Bundle Resource

Following code is tested and you can able to access zip file through it : 以下代码经过测试,您可以通过它访问zip文件:

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")

暂无
暂无

声明:本站的技术帖子网页,遵循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: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” URL(fileURLWithPath:Bundle.main.path(forResource:“ ports”,ofType:“ geojson”)!)是零吗? - URL(fileURLWithPath: Bundle.main.path(forResource: “ports”, ofType: “geojson”)!) is nil? 为什么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