Justin808
Justin808

Reputation: 21512

xcode - copy a folder structure into my app bundle

I have a folder structure 10 deep or so. I need to copy that full structure into my app resource folder. Is there an easier way than manually recreating it with 100s of copy phases for each of the folders?

Upvotes: 11

Views: 9033

Answers (2)

Kai Oezer
Kai Oezer

Reputation: 124

It is still the same in Xcode 12: Check the Create folder references box when adding the root folder of your folder structure to the project.

Group hierarchy in project navigator - before

Source folder hierarchy in Finder

Add files to folder

Group hierarchy in project navigator - after

Resulting folder hierarchy in-app bundle

To access the resources in code, specify the subdirectory path in your call to Bundle.url():

Bundle.main.url(forResource: "blabla",
                withExtension: "txt",
                subdirectory: "A/B/C/D")

Upvotes: 7

Abhi Beckert
Abhi Beckert

Reputation: 33329

When you add a directory to Xcode, there is a tickbox (on by default) to convert folders into groups.

Turn that off, and it will do what you want.

Upvotes: 22

Related Questions