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