0

I have a iOS project with a folder/group structure like this:

enter image description here

Xcode copies lesson.xml to my bundle without the enclosing folders, so I need to load it like this:

let url = Bundle.main.url(forResource: "lesson", withExtension: "xml")

But I'd like the folders in the bundle, so I can have multiple lesson.xml files and load them like this:

let url1 = Bundle.main.url(forResource: "Lessons/Hello/lesson",
                           withExtension: "xml")
let url2 = Bundle.main.url(forResource: "Lessons/Foo/lesson",
                           withExtension: "xml")

How do you copy a folder structure to the bundle?

Rob N
  • 15,024
  • 17
  • 92
  • 165
  • There's not an easy way to do it. You'd have to add separate Copy Files phases for each destination folder. And you don't have to include the extension in the `forResource` argument if you've specified it in the `withExtension`. – NRitH Mar 19 '18 at 00:09
  • Thanks, I just tried it and that works. Also I'll edit the question to remove the duplicated extension. – Rob N Mar 19 '18 at 02:47
  • There IS an easy way. Use folder references instead of mere groups as you are doing now. – matt Mar 19 '18 at 02:57
  • Thanks, that works too. (Deleted my previous comment. I just need to drag the folder in, not use "add files" menu item.) – Rob N Mar 19 '18 at 03:13
  • Basically they are identical. Just two ways of making a folder reference. – matt Mar 19 '18 at 03:24

0 Answers0