How to get path to a subfolder in main bundle?

半世苍凉 提交于 2019-11-29 13:59:27
dasblinkenlight

In Swift-3 make URL, and call appendingPathComponent:

let resourcePath = Bundle.main.resourcePath
let subdir = URL(fileURLWithPath:resourcePath!).appendingPathComponent("sub").path

or simply

let subdir = Bundle.main.resourceURL!.appendingPathComponent("sub").path

(thanks, Martin R!)

See this Q&A on information on stringByAppendingPathComponent method in Swift.

You can use this method to get listing of the bundle subdirectory and get resources only of the specific type:

Bundle.main.paths(forResourcesOfType: type, inDirectory: folder)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!