![](/img/trans.png)
[英]Bundle.main.path(forResource:ofType:inDirectory:) returns nil
[英]Bundle.main.path(forResource:) returns nil
由於我未知的原因,我無法找到文件:
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")
EDIT2:我通過檢查我的資源文件夾並檢查其內容來驗證它是否存在:
Bundle.main.resourcePath
FileManager.default.contentsOfDirectory(atPath: myResourcesFolder)
另外,我已經在finder中檢查了它是否確實存在。
它包含在副本捆綁資源中:
感謝https://stackoverflow.com/users/1187415/martin-r:iOS設備上的文件系統區分大小寫:“ zip”!=“ ZIP”。 更改為ZIP后,它可以完美運行。
首先是通過查看“ Copy Bundle Resource
來檢查是否在添加時將該ZIP文件復制到Copy Bundle Resource
。
以下代碼經過測試,您可以通過它訪問zip文件:
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.