Xcode 4 Transition Guide
Xcode 4 Transition Guide
Guide
Contents
Orientation to Xcode 4 22
Much of Your Project’s Content Is in New Locations 22
Set Build Settings for Each Target 23
Set Basic Build Settings 25
Set Up a Sandbox for Each Target 25
Select Any File to Open an Editor 27
Write and Edit Source Code 27
Speed Up Typing with Code Completion 28
Have Fix-it Flag Errors as You Type 30
Open a File in the Assistant Editor Pane 30
View Files in Hexadecimal Format 30
2
Contents
3
Contents
4
Figures
Orientation to Xcode 4 22
Figure 3-1 Target information in the project editor 23
Figure 3-2 Build settings 24
Figure 3-3 The Mac OS X summary pane 25
Figure 3-4 Mac OS X entitlements editor 26
Figure 3-5 Entitlements property list 27
Figure 3-6 Code completion 28
Figure 3-7 Quick help for code completion 29
Figure 3-8 Code completion underlining 29
Figure 3-9 Fix-it in action 30
Figure 3-10 The Scheme pop-up menu 32
Figure 3-11 The scheme editor Build pane 33
Figure 3-12 Customizing an executable environment for a product 34
Figure 3-13 The find navigator 35
Figure 3-14 The Find Options dialog 36
Figure 3-15 The symbol navigator 37
Figure 3-16 The symbol navigator, filtered 38
Figure 3-17 A symbol displayed in the source editor 38
Figure 3-18 Using the jump bar to find a symbol 39
Figure 3-19 The related-items pop-up menu 39
Figure 3-20 The project navigator filtered to show only .m files 40
Figure 3-21 Run diagnostic options 42
Figure 3-22 Behaviors preferences 43
Figure 3-23 Naming a tab 44
5
Figures
6
Figures
7
About the Transition to Xcode 4
Xcode 4 is the latest iteration of Apple’s integrated development environment (IDE). This document is intended
for developers who are familiar with Xcode 3 and want to get started quickly using Xcode 4. If you want a short
tutorial that introduces you to the major features of Xcode 4, see Xcode Quick Start Guide . If you want a more
complete introduction to the features and workflows of Xcode 4, see Xcode 4 User Guide .
Figure I-1 shows the main user interface elements described in this document.
Xcode 4 uses one type of main window, called the workspace window , to hold most of the data you need. You
can have as many workspace windows open as you need. A second window, called the Organizer window, is
used for organizing your projects and reading documentation. For iOS projects, the Organizer window is also
used for managing devices.
At a Glance
There are many improvements and new features in Xcode 4. A very partial list includes:
● Xcode 4 has a new, single-window interface for all major workflows (you can have multiple workspace
windows and multiple tabs per window).
● Interface Builder is fully integrated with the main Xcode application.
8
About the Transition to Xcode 4
At a Glance
● Assistant provides a second editor pane that complements the file you’re working on—for example, if
you’re working on an implementation file, it can automatically find and open the corresponding header
file.
● Fix-it checks your symbol names and code syntax as you type, highlights any errors it detects, and in some
cases can even fix them for you.
● The version editor works with Git or Subversion to show a file’s entire SCM history and compare any two
versions of a file.
● The LLVM 2.0 compiler includes full support for C, Objective-C, and C++.
● The LLDB debugger is faster and uses less memory than the GDB debugging engine.
● Xcode 4 lets you work on several interdependent projects in the same window, automatically determining
dependencies so that it builds the projects in the right order.
Relevant Chapters: “Using an Existing Xcode 3 Project” (page 11), “Creating a New Xcode 4 Project” (page 21).
9
About the Transition to Xcode 4
At a Glance
Relevant Chapters: “Orientation to Xcode 4” (page 22), “Debugging and Analyzing Your Code” (page 77),
“Replacing Text and Refactoring” (page 89).
10
Using an Existing Xcode 3 Project
If you’ve been working in Xcode 3 and have one or more Xcode 3 projects that you’d like to use in Xcode 4,
this chapter tells you what you need to know to get started. After you’ve opened your projects, go to “Orientation
to Xcode 4” (page 22) to learn more about using Xcode 4.
Xcode 4 reads and builds projects created in Xcode 2.1 through the latest release of Xcode 3. Projects created
with Xcode 4 can be opened and built on Xcode 3.2 and later.
You can open a project in either application, save it, then open it in the other application without invalidating
the project or losing any data. Changes you make to a project in Xcode 4 remain compatible with earlier
versions of Xcode.
11
Using an Existing Xcode 3 Project
See Your Groups and Files
12
Using an Existing Xcode 3 Project
See Your Groups and Files
The left side of the window is the navigation area, opened to the project navigator, which is similar to the
Groups & Files list in the Xcode 3 project window. Figure 1-2 shows the contents of an Xcode 3 project as seen
in Xcode 4.
What you see in this list is probably less surprising than what you don’t see. Missing from the Xcode 4 project
navigator are these groups:
● Targets
● Executables
● Find Results
● Project Symbols
● Bookmarks
● SCM (source control repositories)
● Smart groups
You’ll also notice that the detail view is missing from Xcode 4.
The Xcode 4 equivalents to these groups and user interface elements are described in “Orientation to Xcode
4” (page 22).
13
Using an Existing Xcode 3 Project
Replace Your Interface Builder Plug-ins
Xcode 4 ignores your Xcode 3 General, Code Sense, Building, Distributed Builds, Debugging, Key Bindings, File
Types, Source Trees, and Documentation preferences. Similar Xcode 4 features start with Xcode 4 defaults.
Changing settings in Xcode 4 does not affect your settings for these preferences in Xcode 3.
14
Using an Existing Xcode 3 Project
Check Out a Working Copy
15
Using an Existing Xcode 3 Project
Check Out a Working Copy
3. Fill in the name you want to use for the repository as displayed in the Organizer window and click Clone
(for Git) or Checkout (for Subversion).
4. In the Save As dialog, specify the name and location you want to use for the working copy and click Clone
(for Git) or Checkout (for Subversion).
5. In the confirmation dialog, click Open to open the new working copy in an Xcode workspace window (for
Git) or Show in Finder to see the new working copy in the Finder (Subversion).
16
Using an Existing Xcode 3 Project
Modernize Your Project
6. For Git, you’re done. For Subversion, click on the name of the new repository in the repositories organizer
and fill in the paths to the trunk, branches, and tags directores. If your Subversion server requires
authentication, fill in the user name and password as well.
See “Repositories, Snapshots, and Archives” (page 95) for more information about source control in Xcode 4.
Open the issue navigator (Figure 1-4) to see whether anything in your project needs to be updated. You can
also select the project in the project navigator and choose Editor > Check for Outdated Settings, or choose
the project from the the drop-down issues menu at the right end of the jump bar.
17
Using an Existing Xcode 3 Project
Work with Multiple Related Projects
If the issue navigator lists modernization issues, click the issue to see a dialog that explains the updates that
should be made (Figure 1-5). Deselect any checkboxes for settings you don’t want to change, then click Perform
Changes to update the project to optimize it for Xcode 4.
After you have clicked Perform Changes, whether you choose to make all the changes or not, Xcode does not
show the warning again. To rerun the check, select your project in the project navigator and choose Check for
Outdated Settings from the Editor menu.
18
Using an Existing Xcode 3 Project
Work with Multiple Related Projects
● Indexing is done across the entire workspace, extending the scope of content-aware features such as code
completion and refactoring.
A project can be included in more than one workspace or removed from a workspace without affecting the
project. The workspace file itself merely contains pointers to the projects and other files that the workspace
includes, plus a minimal amount of data such as schemes stored in the workspace (see “Select a Scheme” (page
31)). The pointers to the source files, included libraries, build configurations, and other data are stored in the
project files.
If you have two or more related projects, use the following procedure to create a workspace and add the
projects to it:
1. If Xcode 4 is not open, start it. You can ignore or cancel the startup screen.
2. Choose File > New > New Workspace and name the new workspace.
3. In the New Workspace dialog, specify the location for the workspace file and the name of the workspace.
If your projects are in the same directory, it might be convenient to put the workspace file in there as well.
To avoid possible confusion with your projects, give the workspace a unique name. Click Save.
19
Using an Existing Xcode 3 Project
Work with Multiple Related Projects
4. Drag projects from the project navigator of other Xcode 4 windows or from the Finder to the project
navigator of the new workspace. When dragging from the Finder, be sure to drag the project file
(<ProjectName>.xcodeproj), not the entire project folder. Be careful to drop each new project below
the last project, not in another project.
If you’ve set up your build configuration with explicit references between your projects, the build will continue
to behave as it did before. If you used to build one project and then import the product into the other project
before you built it, you can remove the product from the project that imports it, because Xcode 4 discovers
such implicit dependencies and builds in the correct sequence. If you don’t want one project to use the product
or files in another project that’s in the same workspace, you need to adjust your build settings accordingly.
See “Set Build Settings for Each Target” (page 23) for help in finding and understanding the build settings
interface in Xcode 4.
Before you build, be sure you’ve created the scheme or schemes you need. See “Select a Scheme” (page 31)
and “Customize Executables” (page 34).
20
Creating a New Xcode 4 Project
If you want to start a new software development undertaking using Xcode 4, you need to first decide whether
you need a single Xcode project or multiple related projects. For a simple application or utility, a single project
should suffice. However, if you have several related executables that need to link against a custom library, you
probably want at least a separate project for the library and another for the executables, and possibly a separate
project for each executable. In that case, see “Create a New Workspace” (page 21).
If you decide later that you want to create a workspace and add your project to it after all, see the instructions
in “Using an Existing Xcode 3 Project” (page 11).
21
Orientation to Xcode 4
Once you’ve got your projects open in Xcode 4, you can start writing code. This chapter describes many of the
features of Xcode 4 that are located in different places, or used somewhat differently, from the same features
in Xcode 3. It also describes a couple of features that are new in Xcode 4. For information in the debugging
features of Xcode 4, see “Debugging and Analyzing Your Code” (page 77). For changes in the workflow of
designing user interfaces using Xcode 4, which has a fully integrated Interface Builder, see “Designing User
Interfaces in Xcode 4” (page 63).
22
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Click the various buttons and icons in the project editor to see the information that’s in there. Note that some
of this information is in the Targets group in Xcode 3, but much of it, although actually related to the target,
is found in other places in Xcode 3. Xcode 4 brings all this information together and makes some of the
relationships clearer.
In particular, in Xcode 3, if you need to alter any build settings or create any custom settings, you need to
select the target in the Groups & Files list and then open the Info window. To change the list of what files were
included in the build or in what order they were used, you need to open all levels of disclosure triangles under
23
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
the target in the Groups & Files list. Although some build settings are specified at the project level, some are
specified at the target level, and some use defaults, these relationships are not obvious in Xcode 3. In Xcode
4, on the other hand, you can view all the levels of build settings simultaneously, as seen in Figure 3-2.
You can edit a build setting at any level. The level at which the build setting is actually set is highlighted in
green. The value to which the build setting is set is listed in the Resolved column. If you have changed or
customized a setting, it’s shown in boldface.
24
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Each setting in the Summary pane is also found in one of the other panes. When you edit a setting, Xcode
updates the other pane automatically.
In Xcode 4.1 and later, the project editor provides a UI for setting up entitlements for Mac OS X applications.
You can set entitlements for each target in the project editor (Figure 3-4). There is also a default code-signing
entitlements file available in the file templates in the utilities pane.
25
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Note Although the Mac OS X sandboxing UI is available in Xcode on v10.6 Snow Leopard, only Mac
OS X v10.7 Lion and later versions of the operating system enforce the entitlements.
26
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
When you enable application sandboxing, you can select an entitlements file if you already have one. If you
do not, Xcode creates one with the name of your project and the extension entitlements. You can view and
edit this file with the property list editor in Xcode (Figure 3-5).
Each document-type editor has custom commands in the Navigate and Editor menus to act on the information
in that document type.
27
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
28
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
A Quick Help pop-up dialog is also available from code completion, even when the Quick Help inspector is not
open. Hold the pointer over the code completion option you’re interested in until a question mark icon appears.
Click the question mark or press Command-Shift-Control-Question Mark to open Quick Help. As before, press
the Tab key to accept the prefix or Return to accept the entire suggestion. Click the Done button in the Quick
Help pop-up dialog to cancel the operation.
If all of the possible completions have a common prefix (NSString in Figure 3-6), the prefix is indicated with
a dotted underline. Press the Tab key to accept only the prefix. Press Return to accept the entire autocompletion
suggestion. If there is no common prefix, code completion shows the dotted underline up to the next uppercase
letter in the symbol (Figure 3-6). Again, press Tab to accept only the subword, or press Return to accept the
entire suggestion.
Press Control–Space bar to toggle the completion suggestion on or off. That is, if the inline suggestion and
list are being displayed, pressing Control–Space bar cancels the code completion operation. If there is no
suggestion displayed, place the cursor at the end of a partially typed symbol and press Control–Space bar to
get completion suggestions.
Note that in Xcode 4, pressing the Esc (Escape) key cancels the operation and pressing the Delete key always
deletes the preceding character.
29
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
You can edit the hexadecimal code directly, or you can edit in the plain text column. Editing either updates
the other.
30
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
When the hex editor has focus, you can use the Editor menu to customize its display.
The preprocessor evaluates directives in your source code (for example, instructions starting with the number
sign (#), such as includes, defines, and conditional logic) and converts them into C code to be sent to the
compiler. You can examine the preprocessed output to make sure that the logic in your source code is being
interpreted by the preprocessor as you expect in order to debug compilation problems.
The assembly output is the set of instructions that the compiler generated from the preprocessed output. You
can study the assembly output to see how the instructions were formed or ordered, to seek out better
optimization patterns, or to look for compiler bugs.
The output type is also a new category in the assistant editor for a selected primary file.
Select a Scheme
In Xcode 3 you have to set an active target, a build configuration, and an executable as separate items. The
problem with this approach is that targets, configurations, and executables are intimately linked. At its simplest,
for example, a target contains one product, which is executed without any special options or environmental
settings. However, sometimes the product requires values for input parameters or other customization before
it can be executed. In Xcode 4, you select a scheme, which specifies which targets to build, what build
configuration to use, which debugger to use, and which executable to launch when you choose Run from the
Product menu or click the Run button at the left end of the toolbar. Each scheme also specifies a set of options
for several possible actions:
● Running a product for debugging
● Running unit tests
● Profiling your application with Instruments
● Performing a static analysis of your code
● Archiving your product for distribution or submission to iTunes Connect
31
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
When you open an existing Xcode project (or create a new one), Xcode 4 automatically creates a scheme for
you. To select a scheme, you use the Scheme pop-up menu in the upper-left corner of the Xcode window
(Figure 3-10). To create a new scheme, choose New Scheme from that menu. To edit existing schemes, choose
the scheme you want to edit and then choose Edit Active Scheme from that menu. To change the list of
schemes, where they’re stored, and whether they’re shared, choose Manage Schemes.
You can have as many schemes as you want, but only one can be active at a time.
32
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
figure, the SurfWriter application and framework are set to be built for every action, but the plug-in is set to
be built only when the application is built for running (that is, for debugging) and for archiving (that is, for
distribution). Each of these actions has associated options that you can customize with the scheme editor.
33
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Customize Executables
To customize the environment in which a product is launched in Xcode 3, you click the executable in the
Groups & Files list and then open the Info window. In Xcode 4, choose Edit Active Scheme from the Scheme
pop-up and choose the product you want to run (Figure 3-12). Note that you can choose to display the running
product at a higher UI resolution to simulate running at a different display resolution.
34
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
35
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
To customize the search, click the magnifying glass in the search field and choose Show Find Options to get
the Find Options dialog (Figure 3-14).
36
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Use the search field and scope buttons at the bottom of the navigator to specify exactly what is listed. The
scope buttons are blue when toggled on and black when off. Use the buttons in any combination:
● —hides symbols other than classes and their members, including protocols, functions, structs, enums,
unions, types, and globals
● —hides symbols defined only in external frameworks, displaying only symbols defined in the project or
workspace,
● —hides member symbols defined within the classes such as methods, properties, and variables
37
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
When you select the Flat button at the top of the symbol navigator, the navigator displays all classes arranged
alphabetically. When you select the Hierarchical button, the navigator displays the class hierarchy.
Use the search field at the bottom of the symbol navigator to filter the results. For example, in Figure 3-16,
only those symbols that include the string KTg are displayed. This filter is not case sensitive.
Click a symbol to see it displayed in the source editor (Figure 3-17). Option-click the file in the symbol navigator
to open Assistant and display the file in the assistant editor pane (see “Split the Editor Area” (page 51)).
38
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
Each of the navigation elements in the jump bar is also a pop-up menu with a list of symbols at that level in
the project hierarchy. The jump bar shows the same structure as seen in the project navigator down to individual
files, and then the symbols in the files. Click one of the navigation elements in the jump bar to see the list and
to select a symbol to display (Figure 3-18). Hold down the Option key when selecting a file in the jump bar to
display the file in the assistant editor pane (see “Split the Editor Area” (page 51)).
The jump bar also has back and forward buttons for moving through previously viewed files, and a pop-up
menu ( ) that displays a variety of useful information about related items, as you can see in Figure 3-19.
39
Orientation to Xcode 4
Much of Your Project’s Content Is in New Locations
In addition to the structure, symbol, and find navigators already discussed, there are navigators that display:
● Warnings, errors, and other issues found when analyzing or building your project
● Threads and stacks in a debugging session
● Breakpoints
● Build logs
For more information on using these navigators to analyze and debug your code, see “Debugging and Analyzing
Your Code” (page 77).
40
Orientation to Xcode 4
Customize the Build and Run Workflow
Note Although Xcode 4 does not allow you to create smart groups and does not display any smart
groups that you created for your project in Xcode 3, it does preserve your Xcode 3 smart groups. If
you open your project in Xcode 4 and work with your code, then later reopen your project in Xcode
3, the smart groups you created earlier are still there.
View Details
All of the information in the detail view has been replaced in Xcode 4 with navigators or editors. Here are some
of the main equivalents:
● Files in your project: use the project navigator (see “Open Your Xcode 3 Project in Xcode 4” (page 11))
● Find results: use the find navigator (see “Search Your Workspace” (page 35))
● Executables: use the scheme editor (see “Customize Executables” (page 34))
● Targets: use the project editor (see “Set Build Settings for Each Target” (page 23))
● Bookmarks: use the bookmarks navigator in the Organizer window for documentation bookmarks (see
“Browse and Bookmark Documents” (page 46))
● Source control: use the source control editor in the Organizer window to work with repositories and the
version editor and project navigator to view source control status of files and to commit or update files
(see “Work with Source Control Repositories” (page 48))
● Project symbols: use the symbol navigator and the jump bar (see “Browse to Project Symbols” (page 37))
41
Orientation to Xcode 4
Customize the Build and Run Workflow
whether to build with debug symbols; which targets are built for each type of action; what debugger to use;
what scripts to run before and after each type of action; arguments to pass to the application on launch; a
variety of diagnostic options (Figure 3-21); and what unit tests to run.
42
Orientation to Xcode 4
Customize the Build and Run Workflow
Once you’ve got one or more schemes set up exactly as you want them, the next thing you may do when
setting up your build and run workflow is to open Xcode preferences and click Behaviors. This preferences
pane lets you specify what should happen when a variety of events occur (Figure 3-22).
For example, you can have Xcode display the debug area when your code pauses at a breakpoint, or it can
display the issues navigator when a build fails. Note that, in addition to the Behaviors preferences setting to
create a snapshot, you can specify that Xcode create a snapshot before a mass-editing operation such as a
refactoring transformation. To do so, select the Snapshots pane in the File > Project Settings dialog. (Snapshots
are discussed in “Take a Snapshot of Your Workspace” (page 95).)
43
Orientation to Xcode 4
Customize the Build and Run Workflow
You can name a tab and specify that tab as the display to use when an event occurs. Then you can set up the
display in that tab exactly as you want it; for instance, with a specific source-code file open in the editor, the
debug area open, the Utility area closed, and the issues navigator open. To name a tab, double-click the title
of the tab and type in the new name (Figure 3-23). Tab names are case sensitive in the Show Tab field of Alerts
preferences.
When Xcode reopens the named tab, it remembers the tab’s state—including which window it was in. By
naming a tab in a separate window, you can use the Show tab option in Behaviors preferences to automatically
open a new window. To do so, create a named tab, set it up exactly as you want it, and drag the tab out of the
window to create a new window. Now, each time Xcode recreates the tab, it opens a new window to hold the
tab.
You can also can design custom behaviors that are triggered by menu items or their key equivalents. This
feature allows you to create behaviors that you can invoke at any time. For example, you can create a "Unit
Testing" behavior that creates a snapshot and runs your unit tests (Figure 3-22 (page 43)). After you’ve created
a behavior, it appears in the Xcode > Behaviors menu. To assign key equivalents to custom behaviors, find the
behavior in the Customized tab of the Key Bindings preferences pane.
44
Orientation to Xcode 4
Check on the Progress of Xcode Tasks
Click the number to open a pop-up window that shows the individual status of each current task (Figure 3-25).
45
Orientation to Xcode 4
View Projects, Devices, and Documentation
46
Orientation to Xcode 4
View Projects, Devices, and Documentation
While reading any page of documentation, you can choose Editor > Add Bookmark or Control-click and choose
Add Bookmark for Current Page to bookmark that page. Click the Bookmark button in the navigator pane to
see a list of bookmarks (Figure 3-28).
To select which documentation sets to download, use the Documentation pane in Xcode preferences.
47
Orientation to Xcode 4
View Projects, Devices, and Documentation
Many of the articles in Xcode 4 help include a short video that illustrates the described procedure. Click the
video thumbnail to play the video.
To help you discover and understand the many user interface features of Xcode 4, many of the help articles
are also available as contextual help. See “FInd Answers with Contextual Help” (page 49) for details.
48
Orientation to Xcode 4
Find Answers with Contextual Help
Click the Projects button in the toolbar to display all your projects and their snapshots. See “Take a Snapshot
of Your Workspace” (page 95) for more information on snapshots.
If you’re working with iOS, the Xcode Organizer window also can display the devices that you have connected
to your computer. It indicates which of these devices are currently available and lets you select the one to use.
The iOS organizer in Xcode 4 provides the same information and capabilities as the Xcode 3 Organizer window.
49
Orientation to Xcode 4
Save Changes Automatically
All Help Topics and the help opens in the Organizer window. You can use this facility to find information about
a specific task that you’re trying to accomplish, or just to learn what tasks can be performed using that area
of Xcode 4.
50
Orientation to Xcode 4
Split the Editor Area
Assistant has two modes: tracking (or automatic) mode and manual mode. Tracking mode has several criteria
from which you can choose, such as counterparts, superclasses, subclasses, or siblings. Assistant selects the
file or files that best meet the selected criterion and opens those files in the Assistant pane of the source editor.
In manual mode, you select the file to display in the Assistant pane. You can also split the assistant editor pane
to create multiple assistant editors.
Assistant opens a second pane in the editor area of the workspace window. For source files, the default behavior
for Assistant is to display the counterpart of the file displayed in the standard editor pane. That is, if you’ve
opened an implementation file, Assistant displays the corresponding header file, and vice versa. You can choose
any of several other possible criteria to be used by Assistant using the Assistant pop-up menu. The Assistant
pop-up menu is the first item in the path shown in the jump bar above the assistant editor. To do so, open the
pop-up menu and choose an item, as shown in Figure 3-32. The choices offered depend on the type of file
being edited.
51
Orientation to Xcode 4
Open a New Tab or a New Window
Selecting a file in the project navigator causes that file to be shown in the normal editor pane. Unless Assistant
is set to manual mode (see “Display Content of Your Choosing” (page 52)), it tracks the change. Option-click
when selecting a file in the project navigator or hold down the Option key when selecting a file in the jump
bar to display that file in the Assistant pane rather than the standard pane. Doing so switches Assistant to
manual mode.
The assistant editor pane can be displayed to the right of the standard editor pane or below it. Choose View
> Assistant Layout to switch between a vertical or horizontal split for the editor panes.
52
Orientation to Xcode 4
Open Files with Keyboard Shortcuts
Tabs can be reordered, closed independently, or dragged out of the tab bar to create a new window, just as
they can in Safari. You can use items in the Window menu (or their keyboard equivalents) to move between
tabs.
You can customize the behavior of the single click, Option-click, Option-Shift-click, and double-click keyboard
shortcuts in the General pane of Xcode preferences. Choose one of the following options from each
keyboard-shortcut pop-up menu:
● Primary editor: Opens the file in the primary editor pane in the window and tab already open.
● Focused editor: Opens the file in whichever editor pane currently has focus.
● Single assistant editor: When the navigation originates in a navigator pane or the primary editor (using
the jump bar or the jump to definition command), if the assistant editor is not open or is not split, opens
the file in the assistant editor.
If the assistant editor is split, displays a navigation chooser dialog (“The Single Assistant navigation chooser
dialog”) showing the current layout of editor panes in the window that has focus, with the option of
selecting any open editor pane or adding a new one. Double-click your selected pane, or make your
selection and press Return. Press Esc to cancel.
If the file is already open in one of the editor panes, the navigation chooser displays a star to indicate the
pane containing the file.
When the navigation originates in an assistant editor pane, Xcode opens the file in the primary editor.
53
Orientation to Xcode 4
Open the Utility Area
● Separate assistant editor: If the assistant editor is closed and is not split, opens the file in the assistant
editor.
If the assistant editor is open, opens the file in a new assistant editor pane.
If the assistant editor is split but closed, opens the file in the most-recently-opened assistant editor pane,
replacing the file that was in that pane.
If the file is already open in an assistant editor pane, switches the focus to that pane.
● Separate tab: If the file is not already open in the current window, opens the file in a new tab.
If the file is already open in another tab in the same window, switches the focus to that tab.
● Separate window: If the file is not already open in a separate window, opens the file in a new window.
If the file is already open in a separate window, switches the focus to that window.
The Option-Shift-Click key combination opens a navigation chooser dialog (Figure 3-34) showing the current
layout with the options of selecting any open editor pane in any window and any tab, or adding a new editor
pane, window, or tab. Double-click your selection, or make your selection and press Return. Press Esc to cancel.
The Open Quickly command works in Xcode 4 in much the same way that it worked in Xcode 3. In Xcode 4,
however, you can open a file in the assistant editor by holding the Option key when you double-click or click
Open. To open the file in a separate window, hold down Option-Shift. To see the navigation chooser dialog,
hold down Option-Shift-Click. These behaviors follow the preferences you set for navigation in the General
preferences pane.
54
Orientation to Xcode 4
Open the Utility Area
To open the utility area, choose View > Utilities, or click the Utility button in the toolbar (Figure 3-35).
55
Orientation to Xcode 4
Open the Utility Area
Whereas in Xcode 3, you can make the Quick Help window permanent by moving it from its original location,
in Xcode 4, Quick Help is always available in the Symbol inspector in the utility area (Figure 3-37). Just click
any symbol while the Symbol inspector is open to see its Quick Help information.
56
Orientation to Xcode 4
Open the Utility Area
Quick Help is also available for user interface objects in Interface Builder (Figure 3-38) and for build settings
(Figure 3-39).
57
Orientation to Xcode 4
Open the Utility Area
58
Orientation to Xcode 4
Open the Utility Area
59
Orientation to Xcode 4
Open the Utility Area
● File templates range from templates for applications to subclasses of commonly used Cocoa classes. To
use a template, drag it from the library to a folder in the project navigator. File templates have subcategories,
which you can choose from the pop-up menu below the line of buttons. You can display the templates
as icons only or as icons and text. Regardless of which you choose, when you click a template, an information
window pops open with information about the use of the template (Figure 3-41).
● Code snippets are short pieces of source code that you can use in your software. To use one, you can drag
it directly into your source code file. Alternatively, you can copy a portion of the code from the code
information pop-up window (Figure 3-42) and drag that into your file.
60
Orientation to Xcode 4
Open the Utility Area
To create your own code snippet, highlight the code for the snippet in a source file and drag it into the
Code Snippet library pane. You’ll need to edit the snippet to give it a meaningful name and, optionally, a
completion shortcut. You can use a completion shortcut to add a snippet when editing source code. Type
the shortcut in your source code file and select the snippet from the code completion list to add the code
to your file. Note that a new or edited code snippet is flagged with the word “User” (Figure 3-43).
● Interface Builder objects are used the same way as those in the Xcode 3 Interface Builder. In Xcode 4
they are organized with subcategories and provide information pop-up windows like those for the file
templates and code snippets.
● Media files include a selection of graphics and icons that you can use in your program. All media files in
your workspace or project are listed here.
At the bottom of the library pane is a search field that you can use to filter the library items displayed in the
selected library. In , for example, only the Interface Builder objects whose name or description contains the
word “window” are displayed.Figure 3-38 (page 57)
61
Orientation to Xcode 4
Close a Project or a Workspace
62
Designing User Interfaces in Xcode 4
In the Xcode 3 development environment, Xcode and Interface Builder are separate applications. In Xcode 4,
Interface Builder is an editor within the Xcode application. Although most of the features of the Xcode 3
Interface Builder application work identically in Xcode 4, there are some differences—most notably, the ability
to make connections from Interface Builder objects directly into source code. This chapter describes the main
differences between the two implementations of Interface Builder.
63
Designing User Interfaces in Xcode 4
Create a New Nib File
You can add a new nib file to your project either by choosing File > New > New File and selecting a User
Interface template, or by dragging an interface file from the File Template library into the project navigator.
When dragging into the project navigator, be sure the group into which you want to drop the file is highlighted
before you drop (Figure 4-2); you won’t get the results you want if you accidentally drop the file inside another
file.
Whether you choose New File or drag the nib file from the File Template library, be sure you select the
appropriate file type for the correct platform. For example, there are two nib templates named Application:
one for iPhone and iPad, and one for Cocoa.
64
Designing User Interfaces in Xcode 4
Create New UI Classes in Xcode
65
Designing User Interfaces in Xcode 4
Create New UI Classes in Xcode
Next, add the nib file by selecting a User Interface template of type Window in the New File dialog (Figure 4-4).
66
Designing User Interfaces in Xcode 4
Create New UI Classes in Xcode
Open the new nib file by selecting it in the project navigator so that it appears in the Interface Builder editor.
Then select the File’s Owner object in the Interface Builder dock and choose your controller in the class field
under Custom Class in the Identity inspector (Figure 4-5).
To see the outlets and actions provided by the parent class of the file’s owner, click the File’s Owner object in
the dock and open the Connections inspector. To add new actions or outlets to the nib file’s controller, see
“Make Connections Directly with Source Code” (page 72).
67
Designing User Interfaces in Xcode 4
Create New UI Classes in Xcode
After adding the source file templates to your project, drag a custom view object from the library into the nib
file, as shown in Figure 4-6.
After adding the custom view to your nib, select the custom view and assign the correct class to it in the class
field under Custom Class in the Identity inspector (Figure 4-5 (page 67)).
68
Designing User Interfaces in Xcode 4
Use Assistant to Work on Your UI Code
(Tip: Type nsobject into the search field to find the object quickly.) Select the new object in the dock and
use the class field under Custom Class in the Identity inspector (Figure 4-5 (page 67)) to assign the class of
your controller to the object. Then use the Label field in that same inspector to change its display name.
To see the outlets and actions provided by the controller, click the controller object in the dock and open the
Connections inspector. To add new actions or outlets to the controller, see “Make Connections Directly with
Source Code” (page 72).
69
Designing User Interfaces in Xcode 4
Use Assistant to Work on Your UI Code
pane. If the assistant editor does not automatically display the header file you want, use the assistant editor
pane jump bar to select the source file containing the controller code for the object. Figure 4-8 shows a window
with a graphic view selected in Interface Builder and the header file for the graphic view being chosen from
the Automatic mode of Assistant. By default, the assistant editor pane is displayed below the Interface Builder
editor. Choose View > Assistant Layout to switch between a vertical or horizontal split for the two editor panes.
In Figure 4-9 you can see that, with a window object selected in the Interface Builder pane, the assistant editor
pane displays the file SKTWindowController.m. The oval containing the characters 4/5 at the right end of
the editor jump bar indicates that the fourth of five counterpart files is being displayed (in this case the others
are SKTWindowController.h, SKTGraphicView.h, SKTGraphicView.m, and NSWindow.h). Click the right
or left arrows to display the others in turn.
70
Designing User Interfaces in Xcode 4
Use Assistant to Work on Your UI Code
You can therefore write code for the window controller at the same time you are designing your window, and
you can make connections directly between Interface Builder objects and lines in your code (see “Make
Connections Directly with Source Code” (page 72).
Because Interface Builder is now a fully integrated part of Xcode, it is no longer necessary to switch back and
forth between two applications to create custom subclasses and define actions and outlets. Therefore, Xcode
4 does not provide the special Interface Builder commands used with Xcode 3 to create new subclasses and
copy them into Xcode.
71
Designing User Interfaces in Xcode 4
Make Connections Directly with Source Code
In Xcode 4, on the other hand, you can make the connection directly from the Interface Builder object to the
appropriate header file, and, if needed, Xcode inserts the statement directly into your header file.
72
Designing User Interfaces in Xcode 4
Make Connections Directly with Source Code
If you need to add a new IBAction or IBOutlet statement, Control-drag to the location in the header file
where you want to add the new statement. If the location is a valid connection destination, Xcode displays an
insertion indicator (Figure 4-11). When you release the mouse button, Xcode displays a small dialog where
you specify the nature of the connection (Figure 4-12). Click Connect to insert the code in your header file.
73
Designing User Interfaces in Xcode 4
Get Online Help in IB
74
Designing User Interfaces in Xcode 4
Get More Information on IB
triangle below the placeholders. Note that you can also use the Interface Builder jump bar to select objects in
the interface. To return to the icon view, click the small triangle next to the search field at the bottom of the
list.
Figure 4-14 Outline view for placeholders and objects in Interface Builder
It’s important to note the differences between the work flow in Xcode 4 and the way you do things in Xcode
3. In Xcode 3, if you want to create a new class and use it in an interface file, you have to create the class twice:
once in Xcode, and once in Interface Builder. You need to fully define the class with all outlets and actions,
and connect to those outlets and actions in Interface Builder. You must keep Interface Builder and Xcode
synchronized. By contrast, in Xcode 4, once you’ve created the class, you can connect to the code directly from
Interface Builder (see “Make Connections Directly with Source Code” (page 72)), and Xcode adds outlet and
action code for you. You only need to add the implementation for the actions. If you need to see your new
class in Interface Builder, you can add an object to the Interface Builder editor representing that class, but you
never create a class in Interface Builder.
75
Designing User Interfaces in Xcode 4
Get More Information on IB
If you have worked through the tutorial in the Xcode 3 Interface Builder User Guide , you are already familiar
with the application created in the User Guide tutorial. However, the workflow is quite different.
76
Debugging and Analyzing Your Code
Xcode 4 provides all the facilities you need to analyze and debug your code in the workspace window. This
chapter summarizes those facilities, with an emphasis on differences between Xcode 4 and Xcode 3.
Select a Debugger
Xcode 4 comes with GDB and LLDB debuggers. To select which one to use, choose Edit Active Scheme from
the Scheme pop-up menu (Figure 3-10 (page 32)) and select the Run item in the left column. In the Info pane,
choose the debugger you want to use from the Debugger pop-up menu. Figure 5-1 shows the scheme editor
open to the Run Info pane.
LLDB is a debugger that is part of the LLVM open-source compiler project (see the LLVM home page at
http://llvm.org/). The LLDB debugger is available with Xcode for the first time with Xcode 4. With few exceptions,
the user interfaces for debugging are identical for the two debuggers.
77
Debugging and Analyzing Your Code
Find Potential Problems with Static Analysis
To run the static analyzer, select the project you want to analyze in the project navigator and then choose
Product > Analyze. (If you want to open the scheme editor to set options first, hold down the Option key while
choosing Product > Analyze.) When the analyzer finishes, the issue navigator opens automatically with a list
of the issues found. You can click an issue in the issue navigator to open the file in question. The problem is
labeled in a blue rectangle marked with an arrow. Click the blue rectangle to see the faulty logic flow found
by the analyzer (Figure 5-2).
78
Debugging and Analyzing Your Code
Locate Build Errors
As you can see in the figure, an analysis results bar opens below the jump bar. You can open the analysis
pop-up menu ( ) on the left to see the various issues found, or cycle through them by clicking the arrows at
the right end of the analysis results bar. You can open an issues pop-up menu showing the various files in
which problems were found by clicking the issues button at the right end of the jump bar (see the following
section, “Locate Build Errors”), or cycle through the issues by clicking the arrows that bracket the issues button.
If the compiler finds any problems while building, the issue navigator opens. Select any of the errors or warnings
in the list to display in the source editor the line of code where the problem was discovered. You can display
problems by file or by type (Figure 5-3).
You can also use the issues pop-up menu to navigate through the build issues—for example, if you have the
navigator pane closed to maximize the size of the source editor (Figure 5-4). The issues menu appears as a
yellow triangle if the most serious issue listed is a warning ( ) or as a red octagon if any errors are listed (
79
Debugging and Analyzing Your Code
Locate Build Errors
). Choose an error from the menu or use the arrows to cycle through the errors. If there’s more than one
error associated with a line of code, a number appears at the right end of the error description in the source
editor. Click the number to display a list of all the errors associated with that line of code.
As of Xcode 4.1, you can select what kind of content to view when debugging: source only (when available),
disassembly only, or source and disassembly. The disassembly is the set of assembly-language instructions
seen by the debugger while your program is running. Viewing the disassembly can give you more insight into
what your code is doing when it’s stopped at a breakpoint. By viewing the disassembly and source code
together, you can more easily relate the instruction being executed with the code you wrote.
To view the disassembly while debugging, choose Product > Debug Workflow > Show Disassembly When
Debugging, or open an assistant editor and choose Disassembly from the Assistant pop-up menu in the assistant
editor jump bar.
80
Debugging and Analyzing Your Code
View Build Results
Double-click a warning or error to open the source editor to that error, or open an assistant editor, set it to
Referenced Files, and select an issue in the log to see it displayed in the assistant editor.
81
Debugging and Analyzing Your Code
Manage Breakpoints
Click the list icon ( ) at the end of a build command line to see the full build command and results (Figure
5-6).
Manage Breakpoints
Although you can use the debugger to pause execution of your program at any time and view the state of the
running code, it's usually helpful to set breakpoints before running your executable so you can stop at known
points and view the values of variables in your source code.
To set breakpoints, open a source-code file and click in the gutter next to the spot where you want execution
to stop. When you add a breakpoint to the code, Xcode automatically enables breakpoints, as indicated by
the breakpoint-state button in the toolbar (enabled: disabled: ). You can toggle the enabled state of
breakpoints at any time by clicking the breakpoint-state button. You can also disable an individual breakpoint
by clicking its icon. To remove a breakpoint completely, drag it out of the gutter.
You can set several options for each breakpoint, such as a condition, the number of times to pass the breakpoint
before it’s triggered, or an action to perform when the breakpoint is triggered. To set breakpoint options, open
the breakpoint navigator and Control-click the breakpoint for which you want options (Figure 5-7), then choose
82
Debugging and Analyzing Your Code
Manage Breakpoints
Edit Breakpoint from the shortcut menu. The Condition field lets you specify an execute condition for the
breakpoint. When you specify a condition, the breakpoint is triggered only if the condition (for example, i ==
24) is true. You can use any variables that are in the current scope for that breakpoint. Note that you must cast
any function calls to the appropriate return type.
In addition to conditional breakpoints, which are triggered when a specific condition is met, you can create
exception breakpoints, which are triggered when a specific type of exception is thrown or caught, and symbolic
breakpoints, which are triggered when a specific method or function begins execution. To do so, click the Add
(+) button at the bottom of the breakpoint navigator and choose Add Exception Breakpoint or Add Symbolic
Breakpoint from the pop-up menu.
By default, a new breakpoint is local to the workspace you have open. If you add the project containing that
breakpoint to another workspace, the breakpoint is not copied to the new workspace. You can assign breakpoints
to other scopes, however. If you move a breakpoint to User scope, it appears in all of your projects and
workspaces. If you move a breakpoint to a specific project, then you see this breakpoint whenever you open
83
Debugging and Analyzing Your Code
Examine Threads and Stacks
that project, regardless of which workspace the project is in. To change the scope of a breakpoint, Control-click
the breakpoint and choose the scope from the Move Breakpoint To menu item. The scopes of breakpoints are
shown in the breakpoint navigator (Figure 5-8).
You can share any breakpoints with other users. To share a breakpoint, in the breakpoint navigator, select the
breakpoint you want to share, Control-click the breakpoint, and choose Share Breakpoint from the shortcut
menu. Xcode moves shared breakpoints into their own category in the breakpoint navigator.
84
Debugging and Analyzing Your Code
Control Program Execution
The slider at the bottom of the debug navigator controls how much stack information the debug navigator
displays. At the left end of the slider, the debug navigator shows only the top frame of each stack. At the right
end, it shows all stack frames. Click the button at the left end of the slider ( ) to toggle between displaying
all the active threads or only threads that have your code in them (as opposed to system library code). Figure
5-9 shows the debug navigator when execution has stopped at a breakpoint.
85
Debugging and Analyzing Your Code
Control Program Execution
● Step out of a jumped-to routine; that is, complete the current routine and step to the next routine or back
to the calling routine.
Press Control to step by assembly language instruction instead of by statement (the step icons change to show
a dot rather than a line under the arrow) or Control-Shift to step only into or over the active thread while
holding other threads stopped (the step icons show a dashed rather than solid line under the arrow).
If you pause execution or a breakpoint is triggered, the debug area opens displaying the values of variables
and registers, plus the debug console (Figure 5-10). You can use the buttons at the right end of the debug
area toolbar to display both the variables and console panes or to hide either one.
The variables pane displays variables and registers. You specify which items to display using the pop-up menu
in the top-left corner of the variables pane:
● Auto displays only the variables you’re most likely to be interested in, given the current context.
● Local displays local variables.
● All displays all variables and registers.
86
Debugging and Analyzing Your Code
Control Program Execution
Use the search field to filter the items displayed in the variables pane.
The console pane displays program output and lets you enter commands to the debugger tool. You specify
the type of output the console displays with the pop-up menu in the top-left corner of the console pane:
● All Output displays target and debugger output.
● Debugger Output displays debugger output only.
● Target Output displays target output only.
You can use the navigation pop-up menus in the debug bar to navigate through the threads and stacks (Figure
5-11), or you can use the debug navigator for that purpose.
Figure 5-11 Navigating through threads and stacks in the debug bar
While execution is stopped at a breakpoint, you can view variables and step through code in the source editor
in much the same way as you can in Xcode 3. For example, to continue execution to a specific line of code,
hold the pointer over the gutter next to the target code line until the continue-to-here icon appears, then click
the icon (Figure 5-12).
87
Debugging and Analyzing Your Code
Control Program Execution
To see the values of variables, click the variable name in the editor (Figure 5-13). Hover over and click variable
components to open the disclosure triangles to see the fields of structures.
88
Replacing Text and Refactoring
Like Xcode 3, Xcode 4 enables you to replace text throughout your project and to make other global changes
to your code, such as converting the code to Objective-C 2.0 or creating a superclass from a class. These facilities
are referred to as search and replace and factoring .
89
Replacing Text and Refactoring
FInd and Replace Text
cursor is in the upper text field, so if you get no results after typing your replacement text, put your cursor in
the upper text field and press Return. The activity viewer in the workspace toolbar indicates the find operation
is in progress (Figure 6-3).
90
Replacing Text and Refactoring
Preview Changes
Click Replace All to replace every occurrence of the searched-for text with the replacement text. To replace a
single result, click that result to select it and press Replace. To replace a subset of the occurrences found, use
Shift-click or Command-click to make your selection and press Replace.
By default, Xcode creates a snapshot of your project before making the changes; see “Take a Snapshot of Your
Workspace” (page 95)). To change this preference, select the Snapshots pane in the File > Project Settings
dialog. You can also make a manual snapshot before clicking the Replace button (choose File > Manual
Snapshot).
Preview Changes
To see what your changes will look like in your source code before deciding which occurrences to replace,
click the Preview button below the Replace text box (Figure 6-2 (page 90)). The preview dialog is shown in
Figure 6-4.
91
Replacing Text and Refactoring
Refactor Your Code
To select an individual occurrence of the Find text for replacement, click the checkbox for that occurrence in
the left pane of the dialog, or click the sliding switch in the center of the right pane. Alternatively, you can
select as many occurrences as you wish in the left pane using Shift-click or Command-click, and then press the
Space bar to select them. If you decide to replace all the occurrences, click Cancel and then click the Replace
All button.
Once you’ve selected the text and the refactoring operation, Xcode presents a dialog to let you select options
and specify symbol names where necessary.
92
Replacing Text and Refactoring
Refactor Your Code
You also have the opportunity to preview the changes and decide which files to include before applying the
changes (Figure 6-5). Uncheck a file in the navigator pane to leave it out of the refactoring operation. You can
edit your source code directly in the Preview dialog. Any such edits are shown in the preview and included in
the refactoring operation.
93
Replacing Text and Refactoring
Refactor Your Code
● Move Down moves the declaration and definition of the refactoring item to one or more of the subclasses
of the class that declares and defines the item; select a symbol that is an instance variable in a class, not
a category, where the class is defined in your project and one or more subclasses already exist.
Before you’ve saved your updated files, you can use the Edit > Undo operation on a per-file basis to back out
changes, or you can close the project without saving changes to revert to your original files.
94
Repositories, Snapshots, and Archives
Xcode 4 supports source control repositories for Subversion and Git. It also provides a new snapshot facility
that is much faster than the one in Xcode 3. In addition, whenever you build a target for distribution, Xcode 4
saves an archive of the build products.
Note that you must have installed the Git tool by selecting System Tools in the Xcode 4 installer in order to
use snapshots.
To create a snapshot manually, choose File > Create Snapshot. In addition, by default Xcode 4 creates a snapshot
automatically before a major change such as refactoring your code or executing a find-and-replace operation.
Choose File > Project Settings (or Workspace Settings) to change this option.
To see the snapshots for a project or workspace, click the project in the Projects pane of the Organizer window.
In Xcode 4.1 and later, to restore a snapshot, choose Restore Snapshot from the File menu and select the
snapshot to restore. Xcode displays a preview dialog in which you can review the differences between the
current version of the project and the snapshot version. When you click Restore, Xcode replaces the current
version of the project with the version in the snapshot. Xcode makes a snapshot of the current version before
replacing it.
95
Repositories, Snapshots, and Archives
Take a Snapshot of Your Workspace
To restore a snapshot in a new location instead of restoring on top of the current project, select the project in
the Projects pane of the Organizer window, choose the snapshot you want to restore, and click the Export
Snapshot button at the bottom of the window (Figure 7-1).
Note that, because Xcode 4 keeps track of all your projects and displays them in the Projects pane of the
Organizer even if they no longer exist, you can restore a deleted project from a snapshot.
96
Repositories, Snapshots, and Archives
Keep Track of Changes and Coordinate Work Groups
Xcode 4 provides a consistent user interface for both Subversion and Git. For example, the Subversion UI now
supports annotations. The Xcode 4 installer installs the Git and Subversion tools when you select System Tools.
SCM status is shown as a badge in the project navigator (Figure 7-3), as follows:
M Locally modified
U Updated in repository
A Locally added
D Locally deleted
I Ignored
97
Repositories, Snapshots, and Archives
Keep Track of Changes and Coordinate Work Groups
– The contents of the folder have mixed status; display the contents to see individual status
Badges propagate up to the highest container so you can see the source control status of the whole workspace
regardless of the disclosure level. Detailed SCM status is shown in the Source Control area of the File inspector
in the utility area.
Source control commands are now in the Source Control submenu of the File menu, rather than in a separate
SCM menu. When you’ve made changes to files and saved them locally, use the project navigator to select the
individual files for which you want to perform a source control operation, and choose the action you wish to
perform from the File > Source Control menu (Figure 7-4). Saving a file is not the same as committing it to
source control; you must explicitly commit the file. To see which files have been modified locally but not
committed, look for the M badge next to the filename in the project navigator. You can use the SCM status
filter at the bottom of the project navigator to display only files with SCM status.
Update and commit operations are recorded in the log navigator. Select a log to see the individual steps of
that operation in the editor pane.
98
Repositories, Snapshots, and Archives
Keep Track of Changes and Coordinate Work Groups
Note that you must have installed the Git tool by checking the System Tools check box in the Xcode installer
in order to create and use a Git repository. This check box is enabled by default.
When you choose Commit, a confirmation dialog opens that you can use to make sure the changes you are
committing are what you intended (“Commit Files to Add Them to a Repository”). You can compare your new
version with any past version in the confirmation dialog. When you choose File > Source Control > Commit,
the confirmation dialog shows all the files with pending changes. Uncheck the checkboxes next to any files
that you do not wish to commit. When you choose Source Control > Commit Selected Files from the shortcut
menu in the project navigator, only the files you’ve selected in the project navigator are included in the
99
Repositories, Snapshots, and Archives
Keep Track of Changes and Coordinate Work Groups
confirmation dialog. In either case, you must enter a comment before committing. You can edit the file in the
confirmation dialog before committing. Any changes you make this way are included in the committed file
and saved in your project.
To do so, save and commit any changes, switch to the branch into which you want to merge code, and choose
File > Source Control > Merge. In the Merge dialog (Figure 7-6 (page 101)), the left pane shows what the merged
file will look like. The right pane shows the file with which you’re merging. For each difference or conflict
between the files, an arrow in the center points to the file taking precedence. For example, if the file on the
100
Repositories, Snapshots, and Archives
Keep Track of Changes and Coordinate Work Groups
right (the one with which you’re merging) has a line of code missing from the file on the left (your working
copy) and the arrow is pointing toward the file on the right, then the line of code will be included in the working
copy after the merge operation is complete.
For each difference or conflict, you can use the left and right arrow buttons at the bottom of the dialog to
specify which file’s contents should be used. Therefore, to use the contents of the working copy to resolve the
top difference in the figure, click on the arrow for that difference and then click on the left arrow button at the
bottom of the dialog. Because this line is missing from the current working copy, it is no longer shown in the
left pane. In the case of a conflict, there are two additional options for reconciling differences: you can take
the code lines from both files, either listing the ones in the left (working copy) file first and those in the right
(root copy) file second, or vice versa.
If you wish, you can edit the current branch in the dialog to reconcile any differences not handled by the four
choices. Click Merge and commit the changes to the updated files to complete the operation.
101
Repositories, Snapshots, and Archives
Compare Revisions
Compare Revisions
Select any file under source control and click the Version Editor button ( ) to display two versions
of that file in a side-by-side view. Use the jump bar underneath either editor pane to select the version of the
file to compare with the one in the other pane (Figure 7-8 (page 103)).
102
Repositories, Snapshots, and Archives
Compare Revisions
Buttons under the version editor allow you to show a file comparison and timeline, change logs for the file, or
individual change annotations (“blame”) for each line of the file.
Figure 7-8 Comparing two revisions of a file with the version editor
You can edit the current working copy of the file in the version editor and you can copy code from an older
version and paste it into the current version. In Xcode 4, the working copy of a file is on the left.
103
Repositories, Snapshots, and Archives
Compare Revisions
104
Repositories, Snapshots, and Archives
Compare Revisions
Each log entry is aligned with the line in the file where the change was made. The log entry includes the name
of the person who committed the change, the date, and the ID of the commit. Next to the entry is an arrow
button. Figure 7-10 shows Blame mode in use.
Click the arrow next to any change that interests you to see that change displayed in Comparison mode. Use
the Up Arrow and Down Arrow keys on the keyboard to highlight the change associated with this Blame-mode
entry.
105
Repositories, Snapshots, and Archives
Distribute Your Program or Submit an Application
106
Repositories, Snapshots, and Archives
Distribute Your Program or Submit an Application
To see the archives for your project, open the Archives Organizer window (Figure 7-10). To submit your
application to the app store, you must have an iTunes Connect account. Click Submit to submit the application.
Click Validate to run the same validation used by iTunes Connect to make sure your application is ready for
submittal. To get a copy of your application that you can package for distribution or share with others, click
Share. You can add a comment by clicking on the text field in the Comment column.
107
Document Revision History
Date Notes
2011-07-07 Added information about features new in Xcode 4.1, including Interface
Builder plug-ins and automatic project updates.
2011-02-08 New document that explains how to get started using Xcode 4 if you're
already familiar with Xcode 3.
108
Apple Inc.
© 2011 Apple Inc.
All rights reserved.