【发布时间】:2019-06-30 10:37:48
【问题描述】:
由于我不知道的原因,我找不到文件:
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: ".zip")
这很奇怪,因为当我列出资源目录中存在的所有文件时,它就在那里。我可以找到其他文件,但不是这个。 我也尝试过不同的搜索配置,例如:
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: nil)
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: "")
但没有成功。
编辑: 以下也失败了:
Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")
编辑2: 我通过检查我的资源文件夹并检查其内容来验证它是否存在:
Bundle.main.resourcePath
FileManager.default.contentsOfDirectory(atPath: myResourcesFolder)
我还检查了查找器,它确实在那里。
它包含在副本捆绑资源中:
【问题讨论】:
-
你是如何验证文件是存在于资源中的?
-
检查你是否有这个文件到你的
Copy bundle resource -
iOS 设备上的文件系统区分大小写:"zip" != "ZIP"
-
@MartinR 欠你一杯好啤酒 :D