50

Is there a way to have directories within an .app?

At the moment if I add a file into Xcode, regardless of what Group hierarchy it is in, the file always lands in a flat filesystem within my application bundle.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
gak
  • 32,061
  • 28
  • 119
  • 154
  • I believe this also applies to OS X applications too. – gak Sep 04 '11 at 03:33
  • 1
    FYI, the Group hierarchy in Xcode is pretend. Just a convenience for grouping files Xcode's listings. Does not represent or create folders/directories. – Basil Bourque Aug 17 '12 at 23:44

2 Answers2

93

If you just want to copy existing files into your application bundle's Resources folder (which on iPhone is just the inside of the .app bundle), do the following:

  • Drag the folder you want copied into the Files and Folders listing of your xcode project.
  • From the sheet that pops up asking you if you want to add the files to a target, change the radio button to "Create folder references for any added folders'.

The folder you dragged in and all of its contents will be copied verbatim during building.

Jason Harris
  • 2,317
  • 17
  • 10
  • This works prefect! I get a hierarchy of blue folders in my project hierarchy and the folders gets added to my Copy Bundle Resources. First try I missed the "Create folder references for any added folders", but after revisit the instructions (stupid dyslexia), it works like a charm. – Johan Carlsson Sep 15 '09 at 19:35
  • By the way, you should promote this answer which is more helpful then Jasons, in my opinion. – Johan Carlsson Sep 15 '09 at 19:37
  • 1
    Ive re-accepted the answer to this one, since it's much easier (and obvious) to do. – gak Oct 29 '09 at 09:08
  • Always wondered what difference the folder references really made under the hood. Thanks for sharing this. Very very useful. – imnk Jun 14 '13 at 13:11
17

Under the target for your application, you have to add a Copy Files phase. Then you can specify a sub-directory within the app bundle that you want the file copied to. There will be a bunch of default directories for specific things (like resources and frameworks and such), but you can choose any directory you want. When your application bundle is built, the files you specify will be copied to the location within your bundle.

Jason Coco
  • 77,985
  • 20
  • 184
  • 180
  • 1
    Side note - of the default root places to put files, you probably want to choose "executable" so your subdirectory ends up in the root of your application bundle - then you can look for that subdirectory where you would normally look for other files and then find the file you need within. – Kendall Helmstetter Gelner Jan 08 '09 at 01:08
  • I don't understand. Does this mean replacing the existing Copy Bundle? (what's the point) How do I control which files goes with which copy bundle, or can I only have on (and in fact on sub-directory)? Isn't it possible to make a copy bundle that syncs a file hierarchy? – Johan Carlsson Sep 14 '09 at 16:37
  • 1
    Yes, you can retain the hierarchy of a set of files; copy them to your project and add them as a **folder reference** rather than as a group. Referenced folders are added to an app bundle with their structures intact. – Dalbergia Jun 15 '12 at 17:11