If it is, Xcode quickly replaces the intermediate object fi le in the build folder with the one it precompiled — skipping the need to compile the source fi le again.. The upper pane disp
Trang 1It’s worth noting that running the Clean command is not equivalent to deleting the contents of your build folder, and is one reason that Xcode provides a command to do this There are two potential pitfalls to avoid here: the Clean command might not erase all intermediate items, and deleting the build folder might have unintended consequences The build folder is also the repository for other project support fi les, possibly fi les from other projects The support fi les are used to provide auto-completion, data modeling, predictive compilation, and other intelligent features of Xcode Problems can arise if you impulsively delete these support fi les while Xcode is running Conversely, if you issue a Clean command after removing a target the products of the target you deleted won’t be removed, because they are no longer part of the project.
If you want to ensure that everything in your project is clean, and do so in a way that won’t confound Xcode, follow these steps:
1. Close the project.
2. Trash the project’s build folder.
3. Re-open and build the project.
Xcode automatically re-creates the build folder, along with whatever support
fi les it needs The build folder is normally the folder named “build” inside the project folder — unless you’ve relocated it The “Build Locations” section explains how to change or identify a project’s build location.
PARTIAL BUILDS
There are a few commands for compiling a single fi le without committing a full build These
commands are:
Build ➪ Compile (Command+K) Build ➪ Preprocess
Build ➪ Show Assembly Code Each is enabled whenever you are editing, or have selected, a program source fi le that belongs to
the project Selecting one of these commands compiles the fi le using the current, or only, target that
compiles that fi le
The Compile and Preprocess commands are quick ways of checking that this source fi le compiles,
without waiting for any other fi les or dependent targets to be built The Preprocess command only
runs the fi le though the compiler looking for errors It does not replace the object code last compiled
for the fi le, nor does it perform any other build - related steps
The Show Assembly Code command is a little different It compiles the source fi le using fl ags that
cause the compiler to output assembly source code for the fi le instead of a compiled object fi le This
can be instructive if you need to examine the actual machine code produced by the compiler The
assembly source fi le exists in the build directory and will be overwritten by the next Show Assembly
➤
➤
➤
Trang 2Code command or the next time a clean build is run If you want to compare the assembly code differences between two versions of your source code, you ’ ll have to save or copy the fi rst one before producing another
Xcode also includes a feature called Predictive Compilation You turn this on in the Build tab of the Xcode preferences, explained a little later in this chapter When this feature is enabled, Xcode quietly compiles sources fi les that you have, or are still, editing in the background It does this to
optimize the build process by trying to compile as many source fi les as it can before you request a
build Unless you ’ ve just made sweeping changes to a project, it ’ s likely that most of your source fi les will already be compiled before the build begins
While Xcode is precompiling your source fi les, it saves the precompiled object fi les in a temporary cache Predictive compilation never overwrites any of the intermediate object fi les in your build folder until you start a build When you do fi nally begin the build, Xcode makes one last check
to see whether each precompiled object fi le is still up to date If it is, Xcode quickly replaces the intermediate object fi le in the build folder with the one it precompiled — skipping the need to compile the source fi le again If the precompiled object fi le is not up to date, it is discarded and the build proceeds normally
THE BUILD WINDOW
The build window is your central control for builds, as shown in Figure 17 - 7 Choose Build ➪ Build Results (Command+Shift+B) to open the build window for the active project From the build window, you can start and stop builds, monitor a build ’ s progress, browse errors and warnings, read the detailed build logs, and even correct errors without switching to another window
FIGURE 17-7
Trang 3The build window ’ s toolbar can contain a number of build - related buttons and controls The more
useful are the controls to display and change the active target and build confi guration (described
earlier), the various Build buttons, and the Clean and Clean All buttons Note that the Build button
turns into a Stop Build button whenever a build is in progress
The build window is divided into two panes The upper pane displays progress messages and the
build transcript The lower pane is an editor pane that will automatically focus on the source fi le
associated with the selected issue in the transcript
The items in the transcript pane can be fi ltered and organized in different ways using the controls in
the ribbon at the top of the pane The three groups of controls are as follows:
Choosing All Results shows the results of all recent builds for this project Switching to Latest Results hides the results of previous builds
Choosing By Step or By Issue either groups together the issue, warning, and error messages produced in the step that produced them, or by the type of issue See the section “ Message Groups ” for more details
The Messages control is a drop - down menu that lets you fi lter the items it the build transcript so that it shows:
All build steps and messages Only issues — essentially any message other than completed build steps Only error and warning messages
Only error messages Only static analyzer messages
Build Transcript Items
The build transcript is a structured view of the build log produced by the Xcode tools It takes the
(often voluminous) text output the by the various compilers, tools, and scripts; digests it; compacts
it; and presents it as an intelligent, organized summary of the results Xcode displays fi ve types of
messages in the build transcript window:
Progress Messages Message Groups Build Steps Issue, Warning, and Error Statements Build Summary
Progress messages are transient messages displayed only while a build step (compile, link, copy, and
so on) is in progress Once that step in complete, the progress message is replaced by a completed
build step or it simply disappears Progress messages appear as grey text and let you follow the
activity of your build in detail The CompileXIB statement in Figure 17 - 8 is a progress message
➤
➤
➤
➤
➤
➤
➤
➤
➤
➤
➤
➤
➤
Trang 4FIGURE 17-8
The persistent items that appear in your build transcript are the results of the build These are described in the following sections, and are shown in Figures 17 - 7 and 17 - 8
A build step appears for each completed step in the build, distinguished by a green check mark If the step is associated with a specifi c source fi le, selecting the step displays that fi le in the editor pane
Message Groups
Anytime a build transcript item encompasses one or more submessages, it becomes a message group Use the disclosure triangle to expand or to collapse the group
The build results of each target are contained within a group for that target Collapse the target group if you want to hide (or ignore) the build results for that target
The Choosing By Step or By Issue switch above the build transcript determines whether build issues (warnings, errors, and similar notices) are grouped by step or by type:
By Step groups build issues together in the step where they occurred If a single source fi le produced an error and two warnings, those three issues are grouped in the single Compile step that built that fi le
By Type groups build issues together by type If three different source fi les each contained
a call to a deprecated method, all three messages are grouped together under a single “ is deprecated ” group
Issue, Warning, and Error Statements
The items of most interest in the build transcript are the issues These are the warnings, errors, and
other informational messages that tell you what is, or could be, wrong with your project
Issues are decorated with an icon indicating their type and severity You can selectively fi lter out lesser issues, using the Messages control above the pane, so that the transcript only shows you the
➤
➤
Trang 5more severe problems There are programmers who routinely ignore compiler warnings; they might
set the fi lter to display Errors Only, hiding all warnings and other informational messages I trust
that you ’ re not one of those programmers, but we know they ’ re out there
Build Summary
At the end of each build Xcode inserts a build summary It ’ s a tall — approximately three lines
high — message summarizing the success, or failure, of the build and the time it was started The
build summary conveniently delineates between the results of multiple builds
Transcript Item Text
As mentioned early, the build results that you see in the build window isn ’ t the actual output of the
build It ’ s an interpreted version, with the important bits highlighted and the minutia hidden
Sometimes, however, the details of what went wrong are buried in that minutia When this happens,
you ’ ll want to examine the raw output of the build process There are three techniques for digging
into the details of the build transcript
See the Entire Message
Sometimes the build message is too long to fi t on a single line, or is abbreviated for clarity In either
case, hovering the cursor over the text of the message shows the complete message in a tooltip
Issues that are too long for a single line may also have a “ more ” link at the right edge of the window,
as was shown in Figure 17 - 7 Clicking this link expands the message into multiple lines so you can
read the entire message A “ less ” link appears in the expanded message, which will return it to its
compact state
Reveal the Source Build Output
To the right of some messages is a reveal transcript button, as shown in Figure 17 - 9 Clicking it
reveals the source build output that the message, or messages, were constructed from
Trang 6Right/Control+clicking any message in the build transcript reveals two commands: Expand All Transcripts and Collapse All Transcripts These commands reveal, or hide, the transcripts for every message in the window
Extract Some or All of the Build Log
Right/Control+click any message in the build transcript and choose either the Copy or the Open These Latest Results as Transcript Text fi le command The Copy command copies the raw build log output associated with the selected message to the clipboard
The Open These Latest Results as Transcript Text fi le command — possibly a nominee for the longest command name — exports the entire log from the latest build to a new editor window, where you can sift through it for clues This is particularly useful when looking for problems that don ’ t produce build transcript messages
Navigating Errors and Warnings
Having a concise summary of the problems in your project is only half the battle You have to get
to the source of the problems and fi x them Xcode provides a number of navigation shortcuts for quickly getting to the root of your build issues
Build Window Editor Pane
The build window editor pane is probably the simplest and quickest way to fi x small problems
Select any single message in the build transcript; the associated source fi le (if it has one) is immediately displayed in the editing pane, with the suspect text selected Use the editor to fi x the problem and move on
The View ➪ Zoom Editor In and View ➪ Zoom Editor Out commands work equally well in the build window as they do in the project window Double-clicking the divider bar between the editor and the build transcript also expands
or collapses the pane.
Jumping to the Source
Double - click any build issue and Xcode jumps right to the location in the source fi le that generated the problem You will be transported to either the project window or a separate text editing window, depending on your layout preferences
Issues from the build are used to annotate your source code, so it’s easy to see the location of the issue, a description of the problem, and any other issues in the same fi le The section “ Message Bubbles ” describes this in more detail
Trang 7Jumping to the Next Warning or Error
If your build resulted in a large number of errors, you have my condolences You also have a couple
of commands that will quickly navigate to the next error or warning:
Build ➪ Next Build Warning or Error (Command+=) Build ➪ Previous Build Warning or Error (Shift+Command+=) These two commands jump immediately to the next warning or error in the build transcript If the
build window is active, it jumps to next issue in the list and reveals it in the editor pane of the build
window If you are currently in a separate editing window, the commands skip to the next issue in
that fi le, or opens the next fi le with a problem
Message Bubbles
Though message bubbles were mentioned briefl y in Chapter 6, this is where they become useful —
or annoying, depending on the circumstances Each build issue that ’ s associated with a particular
location in a source fi le appears as a message bubble at that location A build issue indicator appears
in the gutter, and a message bubble describing the issue appears to the right of, or below, the suspect
text, as shown in Figure 17 - 10
➤
➤
FIGURE 17-10
While having the description of the problem appear right where the problem lies is exceptionally
handy, the message bubbles can get in the way of serious editing — particularly when several errors
occur on a single line There are a number of ways to hide, and later reveal, them if they become a
hindrance:
Click on the issue ’ s icon in the gutter View ➪ Message Bubbles ➪ Hide/Show Issues (Shift+Command+H) View ➪ Message Bubbles ➪ All Issues
View ➪ Message Bubbles ➪ Errors & Warnings Only View ➪ Message Bubbles ➪ Errors Only
View ➪ Message Bubbles ➪ Analyzer Results Only
➤
➤
➤
➤
➤
➤
Trang 8Clicking an issue ’ s icon in the gutter toggles the display of that single message bubble The remaining commands selectively hide or reveal all of the message bubbles, or message bubbles of a
particular class The command settings change the message bubbles display for all windows and are
remembered between builds
All of the commands in the View ➪ Message Bubbles menu are also available in the Right/Control+click contextual menu of the editor pane.
BUILD PREFERENCES
The Build tab in the Xcode Preferences, as shown in Figure 17 - 11, is where you ’ ll fi nd a number of global build preferences
FIGURE 17-11
Establishing Common Build Locations
The Place Build Products In and Place Intermediate Build Files In options defi ne the default build locations projects If you have special build locations that should be used for all projects, set them here Otherwise, leave them set to Project Directory and With Build Products The meanings of these locations are described in the “ Build Locations ” section, later in this chapter