Maintain Your Code and Other Resources in Projects or Workspaces
Apps you create in Xcode require a project, which keeps the necessary files and resources organized. You start a project by choosing File > New > New Project. Xcode opens a new workspace window and displays a dialog in which you choose a project template. Xcode provides built-in templates for developing common styles of iOS and Mac apps. These templates include essential project files that help you start your development effort quickly.
You view the names of project files in the project navigator. When you select a file in the project navigator, the file’s contents appear in the appropriate editor or viewer. In this screenshot, an implementation file (
APAViewController.m) is selected in the project navigator, and the file’s contents appear in the source editor.
A Project Is a Repository of Files and Resources for Building Apps
A project contains the elements needed to build one or more apps (or other software products, such as command-line tools and plug-ins). The project also maintains the relationships among these elements. These elements include:
References to source code files (including header files and implementation files), libraries and frameworks, image files, and user interface files
Groups, for organizing files in the project navigator
Project-level build configurations
Targets, each of which produces a single app
By selecting the project name in the project navigator, you open the project editor. You can use the project editor to specify every aspect of how your apps should be built, from the version of the software development kit (SDK) to specific compiler options. In this screenshot, the Adventure project is selected in the project navigator and in the project editor. The project editor displays the Info pane for the Adventure project.
When you create a project, Xcode provides two standard project-level build configurations: debug and release. These configurations differ mostly in whether they include debug information and in the degree to which each build is optimized. These two build configurations are probably sufficient for your product development needs. Most developers never need to change the values of the vast majority of build settings.
To add more build configurations, open the project editor, duplicate one of the project’s existing configurations, and then modify its settings. For example, you might configure a build that’s fully optimized but that also includes debug information in order to debug your optimized code.
Apply App-Specific Settings to a Target
Every project contains at least one target. A target specifies a product to build, such as an iOS or Mac app. Select a target in the project editor to view and modify the target’s settings. In the screenshot below, the Adventure project is selected in the project navigator, and the Adventure iOS target is selected in the project editor. The project editor displays the General pane for the target.
The General pane for a target shows basic settings that you occasionally check and possibly edit. You typically assign values for these settings elsewhere during the app development process, for example, in dialogs that appear when you create a new project.
For an iOS app, the General pane contains these sorts of target settings:
The bundle identifier, a string that identifies the app to the operating system and to the App Store
The version number under which to publish the app
The build number, which identifies a particular build of the app
The name of your Apple Developer Program development team
The deployment target, which is the earliest iOS version on which the app runs
The devices, such as iPhone or iPad, for which to build the app
The main user interface file to load when the app launches
The user interface orientations (portrait, upside down, landscape left, landscape right) that the app supports
For a Mac app, the General pane contains these sorts of target settings:
The application category, for classifying the app on the Mac App Store
The bundle identifier
The version number
The build number
An option for code signing—whether to code sign the app for the Mac App Store, to code sign the app with a developer ID for distribution outside the Mac App Store, or to leave the code unsigned
The deployment target, which is the earliest OS X version on which the app will run
The icon that OS X uses to identify the app to the user
Add Technology Features to a Target
To add various Apple technologies—such as iCloud, Game Center, In-App Purchase, and Maps—to your app, select its target in the project editor and select the Capabilities tab. Click a switch to On to add a capability. Xcode adds the necessary entitlements file to your project and links the target to the necessary frameworks.
Override Build Settings for a Target
A target also contains instructions—in the form of build settings and build phases—for building a product. A target inherits the project’s build settings. Although most developers seldom need to change these, you can override any of the project’s build settings by specifying different settings at the target level. Select a target in the project editor to modify the target settings in the Info, Build Settings, or Build Phases pane.
Workspaces Extend the Scope of Your Workflow
To group Xcode projects and other related files, you can create a workspace. Putting your related projects in the same workspace affords you several benefits. For example:
One project can use the products of another project while building.
If one project depends on the products of another in the same workspace, Xcode can detect this fact and automatically build the projects in the correct sequence.
Because all the files in one project are visible to all the other projects in the workspace, you don’t need to copy shared libraries into each project separately.
You create a workspace by choosing File > New > Workspace. After you create a workspace, you can create new projects within it and you can add existing projects to it.
Close and Reopen a Project or a Workspace
To close a project or workspace, choose File > Close Project or File > Close Workspace. Xcode remembers which windows you had open and how they were configured, and it restores them when you reopen the project or workspace.