Creating Bundles

The first question that comes to mind when talking about application bundles is how do you create the bundle. The good news is you don’t have to do any work to create an application bundle if you use Xcode. Xcode’s Cocoa and Carbon application projects are set up so all you have to do is build the project to create the bundle.

Adding Files to a Bundle

Now that you know how to create an application bundle, a second question comes to mind. How do you get your files into the application bundle?

The Groups and Files list runs along the left side of Xcode’s project window. You should see a Resources folder in the Groups and Files list. Files in the Resources folder will get copied to the Resources folder in the application bundle when you build the project. To add files to the application bundle, you must add them to the Resources folder in your project and build the project.

  1. Select the Resources folder from the Groups and Files list.
  2. Control-click to open a contextual menu.
  3. Choose Add > Existing Files to add the files to your project.

If you want to make sure the files you added will get copied to the application bundle, check to see if they are in the Copy Bundle Resources build phase for your project’s target.

  1. Click the Targets disclosure triangle in the Groups and Files list. You will see a list of your project’s targets.
  2. Click the disclosure triangle next to a target. You will see a list of the target’s build phases.
  3. You should see a Copy Bundle Resources build phase. Click the disclosure triangle next to it.
  4. Make sure the files you added are in the Copy Bundle Resources build phase. If they are not, drag them from the Groups and Files list to the Copy Bundle Resources build phase.

Adding a Folder to a Bundle

If your application uses lots of files, organizing them into folders makes sense. Suppose you have a game with 50 levels, 75 graphics files, and 75 sound files. Throwing all 200 files into the application bundle’s Resources folder would be messy. Having separate folders for the levels, graphics files, and sound files makes finding specific files in the bundle easier. How do you add folders to the application bundle?

Adding folders is no different than adding individual files. Add the folder to your project using the steps I detailed last section. There is one thing to keep in mind. When you add a file or a folder to your Xcode project, you will see the following sheet:

Figure 1

Xcode has two options for adding folders to a project: recursively create groups and creating folder references. Create a folder reference when you want to copy the folder to the application bundle.

Next (Reading Files from the Bundle)

Previous (Introduction)