Xcode, Folders and the File System – Part 1

Xcode provides a built in mechanism for organzing content within a project (control-click or right click -> Add -> New Group). For example, in the image below, I’ve created a number of groups for separating the primary functionality of an application into model classes and views.

Although this is nice, for the most part the file structure as stored on the system is still flat. In other words, Xcode manages this information internally, it does not create corresponding folders on the file system.

In a recent application I was working with large sets of images. The question was, how to best manage all the images within Xcode such that I could leverage the inherent nature of folders and sub-folders on the file system. Let me explain a little further.

From the figure above you can get an idea of how I chose to break down the content. There was a total of 12 models, for each model there were up to 40 images in the folder /coverflow (see the image on the right), a separate folder for wallpaper images, with an image that corresponds to each coverflow image, as well as a handful of other images such a headshot, MenuButton, etc.

On the file system this is a logical breakdown of content, and if I were to use this same structure within the application I could build a path to the appropriate folder in the resource bundle using an index value to specify which folder I am after (/Model-01, /Model-02, etc). This would allow for code that can access the same files, regardless of which model the user selected, no hard-coding of file names and paths.

There were two tricks to get this to work within Xcode. The first trick is to properly import the file contents into Xcode. Here’s how you do that:

Step #1: In the project, right click (control-click) and choose Add -> Existing Files:

Step #2: Choose the folders on the file system to import:

Step #3: After clicking on Add, you will be prompted with the dialog box below. Chose to copy the files into the project as well as create the folder references in the project:


You’ll know that all is well if the folder references appear as blue folders (shown below).

The second trick was to properly reference resources within the application. This was straightforward for images that I wanted the system to cache, however it required a few extra steps for those images I didn’t want cached. More on this, and the code to make it all work, in Part II.

  1. Do you sacrifice control of what subfolders get included for which targets? If I add a folder that includes subfolders, some of which I don’t want included in my Lite version, is there a way to control their exclusion?

Comments are closed.