Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode - copy a folder structure into my app bundle

Tags:

xcode

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?

like image 621
Justin808 Avatar asked Mar 04 '12 00:03

Justin808


2 Answers

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.

like image 116
Abhi Beckert Avatar answered Oct 24 '22 01:10

Abhi Beckert


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")
like image 21
Kai Oezer Avatar answered Oct 24 '22 00:10

Kai Oezer