Get all URLs for resources in sub-directory in Swift

末鹿安然 提交于 2019-12-04 04:32:52

Consider that the yellow folders

are virtual groups, not real folders (although Xcode creates real folders in the project directory). All files in the yellow folders are moved into the Resources directory in the bundle when the app is built.

Real folders in the bundle are

in the project navigator.

You can follow the following steps to get them:

  1. Create a new folder inside your project folder with the extension is .bundle (for example: Images.bundle).
  2. Copy resource files into that new folder.
  3. Drag that new folder into the project that opening in Xcode.
  4. Retrieve the URLs by using the following code snippet:

    let urls = Bundle.main.urls(forResourcesWithExtension: nil, subdirectory: "Images.bundle")
    

You can also view the guide video here: https://youtu.be/SpMaZp0ReEo

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