Important: The information in this document is obsolete and should not be used for new development.
If you created a new project using one of the project templates, or if you converted an existing project, your project will already have a number of groups and files in it, as well as frameworks, folders, and product references. Regardless of whether your project already includes files or was created completely empty, you will likely have to add files or frameworks to your project at some point.
You can add a file, folder, or framework to your project by dragging it from the Finder to the project source group or by choosing Project > Add to Project and using the navigation dialog to choose the item to add.
Adding Files and Folders
Adding Frameworks
Removing Files
There are two ways for you to add files or folders to your project:
In the project window Groups & Files list, select the group to add the files to, and choose Project > Add to Project. Use the resulting dialog to navigate to and choose the file or files to add. If you want to add all of the files in a given folder, you may simply choose the folder. The files or folders you add are placed after the items currently selected in the Groups & Files list, if any.
Drag the icons for the files or folders from the Finder to the project window Groups & Files list. A line shows you where the files will be added.
As a shortcut, you can add a file that is open in an editor window to the project by selecting Project > Add Current File to Project. The editor window must have focus.
Once you have selected the file or files to add to the project, using either of the two methods described above, Xcode displays a dialog, shown below, that allows you to specify how the files are added to the project.
Here is what the dialog contains:
The “Copy items into destination group’s folder (if needed)” option controls whether or not the files are copied into your project folder on disk. If you select this option, Xcode copies over any files that are not already present in the project folder. If the project folder contains subfolders for groups, then the files are copied into the appropriate subfolder.
The Reference Type menu specifies how the location of the file is stored. For a description of the various reference styles available to you, see “How Files Are Referenced.” Note that this menu does not contain any source paths until you have defined one or more source trees in the Xcode Preferences window. Once you have defined a source path, it appears at the bottom of the Reference Type menu and you can choose it for the files and folders you add.
The Text Encoding menu specifies the encoding for the file or files. This is the character set that Xcode uses to display and save a file. For more information on file encodings, see “Choosing File Encodings.”
The Add To Targets group allows you to add the file to one or more of the targets currently defined in your project. If the checkbox next to a target name is checked, the file is added to that target when it is added to the project. When you add a file to a target, that file is built when the target is built. You can specify which files are included in a target at any time; this option allows you to add the file to your project and to any necessary targets in one step.
The remaining options apply only if the selection of files to add to the project includes one or more folders. Xcode can add folders in two ways:
Group. Xcode recursively creates groups for the folder and its subfolders. Each of the files in these folders is added to the project and is placed in the group for the appropriate folder. If you choose to copy the files into the project’s folder, Xcode duplicates the folder hierarchy. If you move a file to the folder outside of Xcode, Xcode does not add the file to the project.
To add a folder as a group, select “Recursively create groups for any added folders.”
Folder Reference. Xcode adds the folder itself to the project but not its contents. This is useful if you need to manipulate the folder as a whole but not the individual items within it. One example is a folder of help files that you edit outside of Xcode and that you want Xcode to move into the application’s Resources folder when you build the application.
To add a folder as a folder reference, select “Create Folder References for any added folders.”
Similar to adding files, you add frameworks to a project by doing either of the following:
Select the
group to add the framework to in the Groups & Files list, and
choose Project > Add to Project. Use the resulting dialog to
navigate to and choose the appropriate framework on the system—for
example, AddressBook.framework.
Drag the framework to the project window Groups & Files list.
After you have selected a framework, Xcode presents the same options described in “Adding Files and Folders.” The following options apply to frameworks:
The Reference Type menu in the dialog specifies how the location of the framework is stored. For a description of the various reference styles available to you, see “How Files Are Referenced.”
The Add to Targets group box allows you to add the framework to one or more of the targets currently defined in your project. If the checkbox next to a target name is checked, the framework is also included in that target when it is added to the project.
The Text Encoding menu specifies the encoding used for the files in the framework. For more information on file encodings, see “Choosing File Encodings.”
You can remove any files, folders, or frameworks from your project by selecting them in the Groups & Files list and pressing Delete. You can also select the files to remove and choose Edit > Delete.
Xcode displays a dialog asking whether you wish to delete the actual files or just the project’s references to them. If you choose Delete References, Xcode deletes only the project’s references to those files; the files remain intact on the disk. If you choose Delete References & Files, Xcode deletes the references from the project, and deletes the referenced files from the disk. The files are deleted immediately; they are not moved to the Trash.
Last updated: 2006-11-07