0% found this document useful (0 votes)
17 views73 pages

Step Into Xcode Mac OS X Development First: Printing Edition Fritz Anderson

The document promotes the book 'Step into Xcode: Mac OS X Development' by Fritz Anderson, which serves as a comprehensive guide for using Xcode to develop applications on Mac OS X. It covers various aspects of Xcode, including its workflow, debugging tools, and application lifecycle, aimed at both newcomers and experienced developers. Additionally, it provides links to download the book and other related ebooks from ebookultra.com.

Uploaded by

moxhiazheem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views73 pages

Step Into Xcode Mac OS X Development First: Printing Edition Fritz Anderson

The document promotes the book 'Step into Xcode: Mac OS X Development' by Fritz Anderson, which serves as a comprehensive guide for using Xcode to develop applications on Mac OS X. It covers various aspects of Xcode, including its workflow, debugging tools, and application lifecycle, aimed at both newcomers and experienced developers. Additionally, it provides links to download the book and other related ebooks from ebookultra.com.

Uploaded by

moxhiazheem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Visit https://ebookultra.

com to download the full version and


explore more ebooks

Step into Xcode Mac OS X Development First


Printing Edition Fritz Anderson

_____ Click the link below to download _____


https://ebookultra.com/download/step-into-xcode-mac-os-
x-development-first-printing-edition-fritz-anderson/

Explore and download more ebooks at ebookultra.com


Here are some suggested products you might be interested in.
Click the link to download

Mastering Mac OS X Third Edition Todd Stauffer

https://ebookultra.com/download/mastering-mac-os-x-third-edition-todd-
stauffer/

Mac OS X Lion Bible 1st Edition Galen Gruman

https://ebookultra.com/download/mac-os-x-lion-bible-1st-edition-galen-
gruman/

Mac OS X Programming 1st ed Edition Dan Sydow

https://ebookultra.com/download/mac-os-x-programming-1st-ed-edition-
dan-sydow/

Easy Mac OS X Lion 2nd Edition Kate Binder

https://ebookultra.com/download/easy-mac-os-x-lion-2nd-edition-kate-
binder/
Learning Unix for Mac OS X 1st Edition Dave Taylor

https://ebookultra.com/download/learning-unix-for-mac-os-x-1st-
edition-dave-taylor/

Mac OS X Developer s Guide 1st Edition Jesse Feiler

https://ebookultra.com/download/mac-os-x-developer-s-guide-1st-
edition-jesse-feiler/

Mac OS X Lion on Demand 2nd Edition Steve Johnson

https://ebookultra.com/download/mac-os-x-lion-on-demand-2nd-edition-
steve-johnson/

Cocoa programming for Mac OS X 2nd Edition Aaron Hillegass

https://ebookultra.com/download/cocoa-programming-for-mac-os-x-2nd-
edition-aaron-hillegass/

Using Mac OS X Snow Leopard 1st Edition Yvonne Johnson

https://ebookultra.com/download/using-mac-os-x-snow-leopard-1st-
edition-yvonne-johnson/
Step into Xcode Mac OS X Development First Printing
Edition Fritz Anderson Digital Instant Download
Author(s): Fritz Anderson
ISBN(s): 9780321334220, 0321334221
Edition: First Printing
File Details: PDF, 10.28 MB
Year: 2006
Language: english
Step into Xcode Mac OS X Development
ByFritz Anderson
...............................................
Publisher:Addison Wesley Professional
Pub Date: January 30, 2006
Print ISBN-10: 0-321-33422-1
Print ISBN-13: 978-0-321-33422-0
Pages:496

Table of Contents | Index

A Step-by-Step Guide to the Xcode Mac OS Development Environment

Every copy of Mac OS X comes with Xcode, the powerful development suite that Apple uses to
build applications ranging from Safari to iTunes. But because Xcode is complex and subtle,
even experienced Mac programmers rarely take full advantage of it. Now, Mac developer Fritz
Anderson has written the definitive introduction and guide to using Xcode to build applications
with any Macintosh technology or language.

Anderson helps you master Xcode's powerful text editor, industry-standard gcc compiler,
graphical interactive debugger, mature UI layout and object linkage editor, and exceptional
optimization tools. One step at a time, you'll develop a command-line utility, then use Xcode
tools to evolve it into a full-fledged Cocoa application. Anderson provides expert guidance on
development frameworks, source code management, Core Data modeling, localization, and
much more.

Coverage includes

Understanding Xcode workflow and the Mac OS X application lifecycle

Porting established legacy projects into Xcode

Using the Model-View-Controller design pattern to build robust graphical applications

Building static libraries and working with Xcode's build system

Making the most of bundles and package directories

Creating applications compatible with older versions of Mac OS X

Creating universal binaries to run on both Intel and PowerPC Macintoshes

Adding Spotlight searchability to data files

Leveraging Xcode's built-in support for unit testing

Using Xcode on makefile-based UNIX development projects


Step Into Xcode 's breadth, depth, and practical focus make it indispensable to every Mac
developer: current Xcode users upgrading to Xcode 2.1, experienced Mac programmers
migrating from CodeWarrior, UNIX/Linux programmers moving to Mac OS X, and even
novices writing their first programs or scripts.
Step into Xcode Mac OS X Development
ByFritz Anderson
...............................................
Publisher:Addison Wesley Professional
Pub Date: January 30, 2006
Print ISBN-10: 0-321-33422-1
Print ISBN-13: 978-0-321-33422-0
Pages:496

Table of Contents | Index

A Step-by-Step Guide to the Xcode Mac OS Development Environment

Every copy of Mac OS X comes with Xcode, the powerful development suite that Apple uses to
build applications ranging from Safari to iTunes. But because Xcode is complex and subtle,
even experienced Mac programmers rarely take full advantage of it. Now, Mac developer Fritz
Anderson has written the definitive introduction and guide to using Xcode to build applications
with any Macintosh technology or language.

Anderson helps you master Xcode's powerful text editor, industry-standard gcc compiler,
graphical interactive debugger, mature UI layout and object linkage editor, and exceptional
optimization tools. One step at a time, you'll develop a command-line utility, then use Xcode
tools to evolve it into a full-fledged Cocoa application. Anderson provides expert guidance on
development frameworks, source code management, Core Data modeling, localization, and
much more.

Coverage includes

Understanding Xcode workflow and the Mac OS X application lifecycle

Porting established legacy projects into Xcode

Using the Model-View-Controller design pattern to build robust graphical applications

Building static libraries and working with Xcode's build system

Making the most of bundles and package directories

Creating applications compatible with older versions of Mac OS X

Creating universal binaries to run on both Intel and PowerPC Macintoshes

Adding Spotlight searchability to data files

Leveraging Xcode's built-in support for unit testing

Using Xcode on makefile-based UNIX development projects


Step Into Xcode 's breadth, depth, and practical focus make it indispensable to every Mac
developer: current Xcode users upgrading to Xcode 2.1, experienced Mac programmers
migrating from CodeWarrior, UNIX/Linux programmers moving to Mac OS X, and even
novices writing their first programs or scripts.
Copyright
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this book, and the publisher was
aware of a trademark claim, the designations have been printed with initial capital letters or in
all capitals.

The author and publisher have taken care in the preparation of this book, but make no
expressed or implied warranty of any kind and assume no responsibility for errors or omissions.
No liability is assumed for incidental or consequential damages in connection with or arising out
of the use of the information or programs contained herein.

The publisher offers excellent discounts on this book when ordered in quantity for bulk
purchases or special sales, which may include electronic versions and/or custom covers and
content particular to your business, training goals, marketing focus, and branding interests. For
more information, please contact:

U. S. Corporate and Government Sales, (800) 382-3419, corpsales@pearsontechgroup.com

For sales outside the U. S., please contact:

International Sales, international@pearsoned.com

Visit us on the Web: www.awprofessional.com

The Safari® Enabled icon on the cover of your favorite technology book means the book is
available through Safari Bookshelf. When you buy this book, you get free access to the online
edition for 45 days.

Safari Bookshelf is an electronic reference library that lets you easily search thousands of
technical books, find code samples, download chapters, and access technical information
whenever and wherever you need it.

To gain 45-day Safari Enabled access to this book:

Go to http://www.awprofessional.com/safarienabled

Complete the brief registration form

Enter the coupon code IDML-RFIM-T1UD-F3M1-GLAW

If you have difficulty registering on Safari Bookshelf or accessing the online edition, please e-
mailcustomer-service@safaribooksonline.com.

Library of Congress Cataloging-in-Publication Data

Anderson, Fritz.
Step into Xcode : Mac OS X development / Fritz Anderson.
p. cm.
Includes bibliographical references and index.
ISBN 0-321-33422-1 (pbk. : alk. paper)
1. Operating systems (Computers)-Software. 2. Macintosh
(Computer)-Software. I. Title.
QA76.76.O63
005.4'465dc22 2005029875
Copyright © 2006 by Pearson Education, Inc.

All rights reserved. Printed in the United States of America. This publication is protected by
copyright, and permission must be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means,
electronic, mechanical, photocopying, recording, or likewise. For information regarding
permissions, write to:

Pearson Education, Inc.


Rights and Contracts Department
75 Arlington Street, Suite 300
Boston, MA 02116
Fax: (617) 848-7047

Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts.

First printing, January 2006

Dedication
For Chrissl,

Nancy, Roger, and Sarah,

who all made this possible.


Preface
From the moment it first published Mac OS X, Apple Computer has made a complete suite of
application-development tools available to every Macintosh user. Since Mac OS X version 10.3,
those tools have been led by Xcode, the development environment that Apple's engineers use
to develop system software and such applications as Safari, iTunes, Mail, and iChat. These
same tools are in your hands.

A solid text editor with syntax coloring and API-based code completion

The industry-standard gcc compiler suite

A graphical, interactive debugger based on the GNU debugger (gdb)

A mature human interface (UI) layout and object-linkage editor for Carbon and Cocoa

Tools for gaining detailed insights into optimizing performance


Audience
I wrote this book for three types of readers.

1. Newcomers curious about the world of Mac OS X development

2. Experienced UNIX-family operating systems users who want an introduction to the Mac
OS X tool set

3. Xcode users wanting to supplement their techniques

Step into Xcode will not attempt to teach programming, a programming language, or any of
the Mac OS X programming frameworks; good books on those subjects have already been
written. My aim is to focus squarely on using the Xcode tool set. Most of the book uses one
example projectnot as a showcase for the programming techniques involved but as a
framework for how to do Mac development with these tools.

The CD-ROM accompanying this book provides the complete project directory bugs and all!for
each chapter. Many of the examples in this book follow the progress of an application project
that begins with a UNIX command line tool and progresses to a Core Databased application
with Spotlight support. As you follow along, you won't have to peck out every file and setting
yourself. The CD-ROM directory, Examples, includes a copy of the project at every major stage
of developmentat least one version for each chapter. You can simply copy the current example
project to your hard drive; the only errors are the ones I made deliberately.
Structure of the Book
Step into Xcode is divided into two parts. Part I introduces Xcode and Mac OS X development
against the background of developing a simple application from a BSD command line tool to a
Tiger-savvy Cocoa application taking advantage of Core Data and Spotlight.

Chapter 1 introduces Xcode with the obligatory "Hello, World" demonstration.

Chapter 2 demonstrates the typical Xcode workflow by building a command line tool that
will form the heart of the application we'll be building throughout Part I.

Chapter 3 moves from passive use of the Xcode debugger to active use, interrupting
program flow to examine the workings of a flawed application.

Chapter 4 shows what happens in compilation and linkage, both generally and in Mac OS
X.

Chapters 5,6, and 7 wrap our command line tool in a Cocoa graphical interface. The
Model-View-Controller design pattern is matched to the tools Xcode provides to
implement it.

Chapter 8 focuses on property lists, a must-know subject in Mac OS X development, and


shows how to create text macros for Xcode.

Chapter 9 moves our command line tool into a static library, showing how to build such a
library and how to integrate a dependent target with Xcode's build system.

Chapter 10 examines bundles and package directories. Most of the targets Xcode can
produce are varieties of bundles. We look at the ubiquitous Info.plist file.

Chapter 11 develops techniques for creating custom view classes for Cocoa and shows
how the development tools support them.

Chapter 12 extends the odyssey of our library from library to framework, showing how to
package a dynamic library and its headers for sharing or for embedding in an application.

Chapter 13 surveys the Xcode options in support of source code management systems.
We set up a local CVS (concurrent versions system) repository and put our project under
SCM (software configuration management) control.

Chapter 14 covers two scenarios for cross-development: creating applications compatible


with versions of Mac OS X earlier than your own and creating universal binaries to run on
both Intel and PowerPC Macintoshes.

Chapter 15 shows how to use the data modeling tool to generate a Core Data model for
our application. After converting our application to use Core Data, many development
tasks become a matter of using Interface Builder.

Chapter 16 examines the techniques used to add Spotlight searchability to our data files.

Chapter 17 finishes up our application with a localization and offers some thoughts on
dead-code stripping.

Part II goes deeper into Xcode usage.

Chapter 18 examines the Xcode human interface and explains how to use it to navigate
projects.
Chapter 19 considers Xcode from the point of view of a developer accustomed to using
CodeWarrior, examining the stumbling blocks on the way to conversion and showing how
to make the Xcode experience more familiar. At the end of the chapter, the notes on
controlling the export of symbols may be useful to non-CodeWarriors.

Chapter 20 looks at Xcode from the point of view of a developer accustomed to working
with makefiles. This chapter describes the build system beneath the IDE (interactive
development environment) and explains how you can customize and control it.

Chapter 21 goes deeper into the debugging tools and techniques introduced in Part I.

Chapter 22 shows how to make Xcode work faster.

Project Builder

Xcode 1.0 was released with Mac OS X version 10.3 (Panther) in September 2003
but has a much longer heritage. Xcode is a development of the Project Builder IDE
used for Mac OS X through 10.2 and for NeXTStep and the NeXT operating system
before that.

Xcode, the result of a rethinking of Project Builder, aimed at streamlining the work-
flow of the typical programmer. Improvements centered on searching and
managing large projects and speeding the edit-compile-link-debug cycle of
development. Xcode added

Code completion

Distributed builds

"Predictive" compilation, using idle CPU time to compile inactive source files in
the background

ZeroLink "lazy" linkage for fast launch times during development

"Fix-and-continue" compilation for changing code while it is running in the


debugger

Version 3 (and now 4) of the gcc compiler

A faster help system in a separate window, with its own search facilities

Speed improvements

Chapter 23 builds a simple AppleScript Studio application and considers Xcode's built-in
support for unit testing.

Chapter 24 shows how to use Xcode on a large open-source makefile-based project, and
how to apply Xcode's debugger and the Shark performance measurement tool to it.

Chapter 25 offers tips, traps, and observations that were left over from the rest of the
book.

Finally, there are two appendixes:


Appendix A reviews how to get the latest version of Xcode and how to install it.

Appendix B lists the major settings variables used by the Xcode build system.
Xcode Versions Covered
This book is based on Xcode version 2.1, released in June 2005, although this version will
probably vary from the one you will use, as Apple has not been timid about reworking Xcode
substantially as performance and usability issues arise. The overall strategies and approach
developed in this bookthe Xcode workflowwill be the same across Xcode versions. For details,
you may have to explore Xcode's menus, inspectors, and preferences; search its help system;
or ask on Apple's mailing list for Xcode users: http://lists.apple.com/mailman/listinfo/xcode-
users.

Most of the material in this book can also be applied to Xcode 1.5, the last version of Xcode for
Mac OS X 10.3.
Typographical Conventions
In this book, code excerpts, symbols, and literal text inputs are set off in this typewriter font.
In interactive text, such as at a terminal, the text you enter is shown in boldface typewriter
font. Boldfacing is also used to emphasize changes to a program listing.

Human-interface elements, such as menu items and button names, are set in boldface text
font. If elements are chained, such as hierarchical lists or menus, each level is set off
by arrows.

Notes are set off in gray boxes.

Sidebars

Sidebars, which contain short digressions on subjects of interest, are set off by
rules above and below.
Acknowledgments
This book was conceived by Ann Sellers at Addison-Wesley, and I hope I've lived up to her
confidence in offering me the opportunity to write it. Greg Doench brought the book through
editing and production. Lara Wysong was tireless in seeing the book into presentable shape;
Evelyn Pyle's copy edits made me look much smarter.

I'd like to acknowledge the help given by David Gleason and Matthew Formica of Apple for
responding to my questions. Matt nudged me into a couple of new directions, and although I
couldn't completely follow his lead, his guidance improved this book.

Here in Chicago, Bob Frank and Jon Rentzsch offered helpful suggestions. And Kate, Bess, and
Selena all showed faith.
Part I: The Life Cycle of a Mac OS X
Application
Chapter 1. Kicking the Tires

Chapter 2. Simple Workflow and Passive Debugging

Chapter 3. Simple Active Debugging

Chapter 4. Compilation: The Basics

Chapter 5. Starting a Cocoa Application

Chapter 6. A Cocoa Application: Views

Chapter 7. A Cocoa Application: Controllers

Chapter 8. Property Lists

Chapter 9. Libraries and Dependent Targets

Chapter 10. File Packages and Bundles

Chapter 11. Creating a Custom View

Chapter 12. Dynamic Libraries and Frameworks

Chapter 13. Version Control

Chapter 14. Cross-Development

Chapter 15. Using the Data Modeling Tools

Chapter 16. Spotlight

Chapter 17. Finishing Touches


Chapter 1. Kicking the Tires
Section 1.1. First Run

Section 1.2. Hello, World

Section 1.3. What Went Where

Section 1.4. Summary


1.1. First Run
Xcode is installed, and it's time to see what it looks like. Find Xcode in /Developer/Applications
and double-click its icon to launch it. If you're running Xcode for the first time, the New User
Assistant window, as seen in Figure 1.1, will be presented.

Figure 1.1. The New User Assistant. The dialog panels in this
assistant capture your preferences the first time you run Xcode.

[View full size image]

The default settings in this window are best for most purposes. Simply click the Next button in
each panel; in the last panel, click Finish. Every setting in the New User Assistant is accessible
through Xcode's Preferences window, so you won't be committing to anything.
FileVault and Xcode

If you are using Mac OS X's FileVault feature to encrypt your home directory, the
New User Assistant's default settings will slow the performance of Xcode
significantly. Compiling and linking an application requires a lot of successive reads
and writes to files, and if FileVault is on, each read and write will have to pass
through the encryption engine. As compiler objects are unlikely to disclose
significant secrets, this is wasted effort.

To avoid this problem, create new folders outside your home directory to hold
intermediate and final build products. One possible location is in the /Users/Shared
directory. In the second panel of the New User Assistant, select the radio buttons
Separate location for build products: and Separate location for
intermediate build files:, and use the Choose . . . buttons to designate the
nonhome directories.

If this is the first time you've run Xcode or this particular version, Xcode will automatically
show you the release notes for the current version. Apple release notes are always worth
readingthey are the only developer documentation written by Apple's engineers, and some
subtleties are found only in the release notesbut for now, close the window. To return to the
release notes, select Show Release Notes in the Help menu.
1.2. Hello, World
We want to get Xcode to do something for us, however minimal. By tradition, this means
building a terminal command that prints Hello, World. Select the New Project . . . command
from the File menu. Xcode presents the New Project Assistant, shown in Figure 1.2.

Figure 1.2. The New Project Assistant. Scroll down to Standard Tool,
select it, and click Next.

Xcode organizes your work around a project , a collection of files, tool settings, and targets . A
target designates the project files used to build a particular product and the tool settings to
apply. The most common kind of project, for building an application, has only one targetfor
building the application itselfbut more complex projects may have several targets: for libraries,
plug-ins, and small tools built ad hoc to test new components.

If you are coming to Xcode from CodeWarrior, the term target is used slightly
differently. An Xcode target corresponds more closely to the CodeWarrior concept of
a product. A CodeWarrior project typically has two targetsdebug and finalfor each
product. Xcode has only one targetcorresponding to the productand any variant in
building a target for debugging or release is a matter of build configurations .

Different target types require different tool settings and system libraries. Xcode eases the
process of configuring a new project by offering you a choice of the most common target types
for the first target in the project. We want to make a simple command line utility that runs in
Mac OS X's BSD UNIX subsystem. Scroll down the list to Command Line Utility and the
subitemStandard Tool (see Figure 1.2), select that item, and click Next.

The next panelNew Standard Tool Assistant (Figure 1.3)lets you name the project and place it
on your disk hierarchy. For this exercise, type HelloWorld in the upper text field to name the
project. The second field will echo what you type, designating ~/HelloWorld/ as the project
directory. This means that the directory HelloWorldwhich will be created if it isn't already
therewill hold your project file , named HelloWorld.xcodeproj, as well as the other files needed
to build your project's targets.

Figure 1.3. The New Standard Tool Assistant. To name a new project,
type the name of the project. The assistant automatically names a
new folder to enclose the project and its files.

Click the Finish button. Xcode creates the HelloWorld directory, copies some files into it, and
opens the project window (Figure 1.4). For a BSD command line tool, the project starts with a
main.c file for the tool's main() function, a HelloWorld.1 template file for the man page, and
theHelloWorld product, shown in red on the screen because Xcode can't find the file associated
with it, which is natural enough, as we haven't built it yet.
Figure 1.4. The HelloWorld project window. Names of files, arranged
in groups, appear in the Groups & Files column at left. The list at
right provides searchable details of whatever is selected in the
Groups & Files column.

[View full size image]

These files are shown in the large detail list in the right-hand portion of the project window.
The contents of the detail list are controlled by the selection in the Groups & Files column.
Selecting the first item under this heading selects the project, filling the detail list with every
file included in the project. Below the project icon are folder icons, representing subgroups of
files; clicking on a folder icon displays in the detail list only the files in that group.

To the left of the project and folder icons are the familiar disclosure triangles. Clicking on a
disclosure triangle opens a container in a list. Expanding a file group folder shows the names of
the individual files in the group.

If you've been exploring, click on the project icon at the top of the Groups & Files column to
restore the list of all files in the detail list under File Name. Now double-click main.c. A window
like the one in Figure 1.5 appears.

Figure 1.5. An editor window, showing the default main.c from the
Xcode command line tool template.

[View full size image]


The placeholder for main() in the default main.c for a command line tool is Hello, World. This
simplifies our first run of Xcode considerably. At the top of the window is a toolbar, the second
item of which is labeled Build and Go. Click that button. A minute may passthe first build of a
target is always longerbut you are soon rewarded with an output window (Figure 1.6) saying
Hello, World! Success.

Figure 1.6. The HelloWorld output window.

Quit Xcode (press command-Q, or select Quit Xcode in the Xcode application menu).
There's nothing to save, so the project and editor windows disappear immediately.
1.3. What Went Where
Switch to the Finder and examine the HelloWorld folder in your home directory (Figure 1.7).
TheHelloWorld directory is right where it was designated in the New Project Assistant and
contains the files HelloWorld.1 and main.c that came automatically with the new project. On
the screen, the blue HelloWorld.xcodeproj icon is the project document file; double-clicking it
opens Xcode and shows the HelloWorld project as you left it.

Figure 1.7. The HelloWorld project in the Finder. Creating and


building a command line tool project in Xcode created a folder for
the project, a project file, some template files, and a build directory
containing the completed tool.

[View full size image]

Thebuild directory contains the HelloWorld tool and a folder named Hello-World.build. This
folder contains a dozen files or so, including the compiled object code from main.c and a
number of files containing indexes to make it easier to navigate large projects and system
libraries. You can ignore the .build directory; its use is strictly internal in Xcode.

TheHelloWorld tool is a genuine UNIX executable, which you can demonstrate by using the
command line terminal. Open the Terminal application in the Utilities subfolder of the
Applications folder. Dragging the HelloWorld tool file's icon from the Finder into the Terminal
window has the effect of "typing" into the terminal the full path of what you dropped. Press the
Return key. The tool runs, prints Hello, World!, and returns to the command line prompt:

xcodeuser$/Users/xcodeuser/HelloWorld/build/Debug/HelloWorld
Hello, World!
xcodeuser$

Tools and applications built with the Debug build configuration, the default, are bound
uniquely to the computer that built them and won't run on other computers. We'll get
to this in Section 4.5.
At this point, we are done with the HelloWorld project. You can drag it and its files into the
trash. Xcode will show no sign of having built or run HelloWorld.
1.4. Summary
In this chapter, we

Ran Xcode and configured it for our use

Created a project to build a command line tool

Executed the tool from inside Xcode

Saw what Xcode does when it creates a project directory and builds a product in it

Verified that the tool we built will run from the command line

Disposed of the project when we no longer needed it


Chapter 2. Simple Workflow and Passive
Debugging
Section 2.1. Linear Regression

Section 2.2. Plan of Action

Section 2.3. A Command Line Tool

Section 2.4. Build Errors

Section 2.5. Simple Debugging

Section 2.6. Summary


2.1. Linear Regression
For most of this book, we'll be working on applications that do linear regression , a simple but
informative statistic. Suppose that you have a series of data pairs, such as the quarterly sales
figures for a particular department, shown in Table 2.1.

Table 2.1. Quarterly Sales Figures


for a Hypothetical Company
(millions of dollars)

Quarter Sales
1 107.5
2 110.3
3 114.5

4 116.0
5 119.3
6 122.4

Aregression line is the straight line that passes nearest all the data points (see Figure 2.1).
The formula for such a line is y = mx + b , or the sales (y) for a given quarter (x) rise at a
quarterly rate (m) from a base at "quarter zero" (b). We have the x and y values; we'd like to
determinem and b.

Figure 2.1. The sales figures from Table 2.1, plotted in a graph. The
line drawn through the data points is the closest straight-line fit for
the data.
The formulas for linear regression are as follows:

The value r is the correlation coefficient , a figure showing how well the regression line models
the data. A value of 0 means that the x and y values have no detectable relation to each other;
±1 indicates that the regression line fits the data perfectly.

Linear regression is used frequently in business and the physical and social sciences. When x
represents time, lines derived from regressions are trends from which past and future values
can be estimated. When x is volume of sales and y is costs, you can claim b as fixed cost and
m as marginal cost. Correlation coefficients, good and bad, form the quantitative heart of
serious arguments about marketing preferences and social injustice.

The demands on a program for turning a series of x and y values into a slope, intercept, and
correlation coefficient are not great: Keep a running total of x, x 2, y, y 2, and xy; keep note of
the count (n); and run the formulas when all the data has been seen.
2.2. Plan of Action
If you're an experienced programmer for UNIX operating systems, the solution to this problem
comes almost by impulse: Write a command line tool that reads data as pairs of floating-point
numbers from standard input and writes m,b, and r to standard output.

Here's the first draft of such a tool:

#include <stdio.h>
#include <math.h>

int main (int argc, const char * argv[]) {


int nScanned;
int n;
double sumX, sumY;
double sumX2, sumY2;
double sumXY;

n = 0;
sumX = sumY = sumX2 = sumY2 = sumY = 0.0;

do {
double x, y;
int nScanned = scanf("%lg %lg" x, y);
if (nScanned == 2) {
n++;
sumX += x;
sumX2 += x * x;
sumY += y;
sumY2 += y * y;
sumXY += x * y;
}
} while (nScanned == 2);
double slope, intercept;
slope = (n * sumXY - sumX * sumY)
/ (n * sumX2 - sumX * sumX);
intercept = (sumY - slope * sumX) / n;

double correlation;
correlation = slope * sqrt((n * sumX2 - sumX * sumX)
/ (n * sumY2 - sumY * sumY));

printf("%g\t%g\t%g\n", slope, intercept, correlation);

return 0;
}

Some veteran C programmers may be surprised to see declarations, such as double


slope, intercept, interspersed with executable statements instead of being gathered
at the top of the enclosing block. Declaring auto variables in the body of code is
permitted by gcc version 3 and later and has been added to the C99 language
standard.

Intermediate-level C programmers will see more than one error in this code. The
errors are intentional.
2.3. A Command Line Tool
Let's put this plan into action. Start Xcode. As you did in the previous chapter, select
Command Line Utility from the list of project types, and name the new project. We'll be
calling the new tool Linrg, so it's most convenient to give the same name to the project.

Once again, Xcode will present you with a project window set up for a BSD UNIX command line
utility. In Chapter 1, we double-clicked on the listing for the main.c file to bring up an editor
window for that file. This time, try clicking once on the main.c file name and then on the
Editor button in the project window's toolbar. The contents of the file appear in the right half
of the project window (Figure 2.2). Selecting different file names in the Groups & Files column
or in the detail list, display the contents of those files in the editor area.

Figure 2.2. Editing the Linrg tool. Note that the small icon next to the
file name main.c in the Groups & Files list and in the file name pop-
up is darkened, indicating that the file has unsaved changes.

[View full size image]

Whether you work in a separate editor windowor in an editor in the project window is
completely up to you. The two views are equivalent. The detail listing that formerly occupied
the right half of the project window is still available. You can have it back by clicking the Editor
toolbar icon again, or you can split the area between them by dragging the split bar that
appears above the editor view or below the detail view. Xcode makes frequent use of
completely closed split views, so be on the lookout for the telltale dimple in a thin bar at the
edge of a view.

The content of main.c is, as before, the Hello, World program, which isn't nearly so useful to us
this time. We substitute the source for our linear-regression tool, and click the Build button in
the toolbar. If you hadn't saved the file before building, a dialog offers to do so before
attempting the build; save the file. I've found that I always want to save changes before
building; by visiting the Building panel of the Preferences window, you can set the Unsaved
Files: pop-up to Always Save.
2.4. Build Errors
All has not gone well. The Xcode icon in the dock now has a red badge with a 1 in it. The status
bar at the bottom of the project window says "Build failed for target 'Linrg' (1 error)." At the
other end of the status bar is an error icon with the count of 1. Looking at the text of the
program, we see the same error icon at the left margin; holding the mouse cursor over the
icon brings up a tooltip saying, "error: parse error before 'x'." Sure enough, as we examine the
line marked by the icon (Figure 2.3), we find that we omitted the comma between the format
string and the second parameter to the scanf() call.

Figure 2.3. Error icon in the margin, from the first attempt at
buildingLinrg. When you point the mouse cursor at the icon, Xcode
pops up a tooltip describing the error.

Searching for errors by hand will not scale well to builds that span many errors among dozens,
or even hundreds, of files. Even Xcode's trick of placing black marks in the scroll bar to mark
the position of errors in the currently edited file only helps a little. Xcode provides a Build
Results window for browsing error messages that arise in the course of building a project. You
can see this window at any time by clicking the Build Results command in the Build menu or
pressingcommand-shift-B. You can also open the Build Results window by clicking the error
icons in the lower-right corner of any editor window.

Open the Build Results window now (Figure 2.4). The top half is taken up with an abbreviated
transcript of the build process, with the single error, "error: parse error before 'x'," highlighted
in red on the screen. Click the highlighted line. The editor view in the bottom half of the window
fills with main.c, centered on the line at which the error was detected.

Figure 2.4. The Build Results window, showing an error in Linrg's


main.c. Clicking the error line focuses the editor pane at the bottom
on the line at which the error was detected. Any file in Xcode can
have multiple editor panes open on it at one time.
It is common for Xcode to present editors for the same file in multiple windows. Source code
may be displayed in the Build Results window, the Project window, Editor windows, the
Debugger window, and even the Source Control window. In each case, the view is a full-
featured, writableto the extent that the target file is writable editor on the file in question. You
can make a change to a file wherever the file appears; Xcode knows that all the views are on
the same file, so there is no danger that the views will get out of sync.

With this in mind, use the editor in the Build Results window to insert a comma after the format
string, and click Build again. Now we are rewarded with the message "Build succeeded for
target 'Linrg'."

Note the cluster of four icons at the lower left of the upper panel of the Build Results window.
Clicking the icon that looks like a document with writing on it opens up the build transcript,
which details the commands used to accomplish the last build and the messages returned by
the tools. This transcript is worth looking at, first, for its value in showing how much goes on
behind the scenes in response to a single command. Second, in the course of advanced tuning
of the build process, this transcript is the only way to see what parameters are getting passed
to the compilers, linkers, and other tools and in what sequence. Third, although it is usually
very good at picking out the informative error messages from what its tools print out, Xcode
isn't perfect. Sometimes, looking at the transcript for the full message is the only way to make
sense of an error.

It's now time to run the Linrg tool. Hold the mouse button down on the Build & Go toolbar
item, and select Run from the drop-down menu. Xcode opens a Run Log window and awaits
our input.

For the first run, let's supply test data on the line y = 2x, adding a little bit of "noise" to make
things more interesting. Type the following into the Run Log window, and press Return:

1.0 2.05

Once again, we have a problem (Figure 2.5). The console prints out the message "Executable
'Linrg' has exited due to signal 10 (SIGBUS)," and the program stops. Mac OS X raises signals
10 (bus error) and 11 (segmentation violation) when a program tries to access memory in a
way that isn't permitted or that hasn't been allocated to its process. In a C program, this
almost always means that a proper value has not been supplied for a pointer.

Figure 2.5. The first runable build of Linrg crashes with a bus-access
error.
2.5. Simple Debugging
Although you may know what the problem with the Linrg tool is, let's prosecute this bug as
though it were a mystery. It is time to start debugging.

Xcode's interactive debugger is a windowed user interface for gdb, the GNU project's interactive
command line debugger. The command line interface to gdb is still available, through a console
window, but most debuggingespecially the simple kind we will do nowcan be done entirely
through the Xcode debugger window. The strategy here is simple: We'll run Linrg again, under
the supervision of the debugger, and let it show us where the crash occurs.

To run usefully under gdb, an application has to be built with settings that preserve information
that relates the binary in memory to the source codethe debugging flag, -gand ensure that the
binary being run works in the same sequence as laid out in the source: -00, the no-
optimization flag. We don't have to do anything to bring these settings about; they are set, by
default, in every new Xcode project.

If you've been following the Linrg example so far, the only thing you need to do is select
Debug Executable from the menu that drops down from the Build & Go toolbar item. If
you've made changes, select Build and Debug instead.

Xcode will take a few extra seconds to start gdb and display its Debug window before it has gdb
executeLinrg. Matters will come to a rest when Linrg is running and looking for data on
standard input.

If you've been using CodeWarrior, you are used to the debugger's pausing before the
first line of main(), waiting for your signal to proceed. Xcode sets no such automatic
breakpoints; if you need to do set-up tasks at the start of execution, you'll have to
set an early breakpoint yourself.

You will see that nothing new will be put into the Run Log window and that typing into that
window will have no effect. For applications being debugged, Apple has chosen to conduct all
standard input and output through a separate I/O window. Select Standard I/O Log from the
Debug menu to display this window: It won't appear automatically, and there is no toolbar
item available to make it visible.

Now, as before, type the following into the I/O window, and press Return:

1.0 2.05

This triggers the crash, but when crashing errors occur in a program being debugged, gdb stops
the program at the site of the crash, and the Xcode debugger displays the state of the
program. See Figure 2.6. The instruction that triggered the error is highlighted in red on the
screen and has a red arrowhead in the margin next to it.

Figure 2.6. The Xcode Debugger window as it appears when the bus
error in Linrg occurs. The machine instruction that caused the crash
is highlighted; the chain of function calls that led to this instruction
is listed in the upper-left panel.
[View full size image]

At first glance, the debugger seems to be doing us no favors: The offending line is highlighted,
yes, but the code in question is in assembly language and appears to be in a system-supplied
library. We were writing in C and were writing an application, not a system library.

Relief, however, is to be found in the panel at the upper left of the debugger window. This
panel lists the chain of function calls that led to the present execution state of the program
being debugged. The current function, _ _svfscanf, is at line 0. This function was called by
scanf (line 1), which in turn was called by main (line 2). This looks promising: We wrote a main
function and called scanf inside it.

CodeWarrior veterans will be used to the debugger's showing the call stack with the
most recent function at the bottom. Under gdb and the Xcode debugger, it's at the
top.

The Xcode debugger displays the first two function names in gray, but main is shown in black.
The debugger displays all function names in the call stack, for which it has access to source
code, in black. What happens if we click on main's item in the list?

The content of the Debugger window changes, most notably in the program listing at the
bottom (Figure 2.7). We recognize this as the main function we wrote. Execution of the
program was stopped inside the call to scanf, and the line containing that call is highlighted.

Figure 2.7. The Xcode debugger's lower, source code, display after
selectingmain in the stack trace. The line containing the call that led
to the place where the program halted is highlighted.
At this point, we can allow at least one scale to fall from our eyes: The scanf function requires
pointers to the variables it fills from standard input, not the values of those variables. As we
have found our error, there is nothing more for the crashed Linrg to tell us. Dispose of its
process by clicking the red Terminate item in the Debugger window's toolbar. Then edit the
line

int nScanned = scanf("%lg %lg", x, y);

to read

int nScanned = scanf("%lg %lg", &x,&y);

Now this bug, at least, is killed.


2.6. Summary
In this chapter, we chose a problem to solve with a computer program and devised a strategy
for solving that problem. We created a command line tool that does standard input and output.
We ran into a compilation error, saw how to get information on the error, and corrected it. We
saw how the Xcode debugger can be used passively to provide an instrument for examining the
state of a program when it has crashed and used the resulting insight to fix a bug.
Chapter 3. Simple Active Debugging
Section 3.1. The Next Step

Section 3.2. Active Debugging

Section 3.3. Summary


3.1. The Next Step
InChapter 2, we got the Linrg command line tool to build without errors and used the Xcode
debugger passively to track down and eliminate an early crashing bug. Let's run our tool again
and see how it goes. Make sure that the project is built, and select Debug Executable from
theBuild and Go menu in the Project window's toolbar.

Once again, we select Standard I/O Log from the Debug menu, so we can interact with
Linrg. Type some data:

1.0 2.05
nan nan nan

Well, after we enter two numbers and press Return,Linrg does not crash. It simply prints nan
nan nan and quits. The status bar in the Debugger and Project windows says, "Debugging of
Executable 'Linrg' ended normally."

Something else is wrong. An illegal floating-point operationsuch as dividing 0 by 0, or square-


rooting a negative numbertook place somewhere in our calculations, resulting in a NaN (not a
number), the special float value that signals an illegal operation. This need have happened only
once; any arithmetic done with a NaN results in a NaN, so a single illegal operation early in the
process could propagate the invalid-result marker through all subsequent calculations.

It makes sense that Linrg should report indeterminate results: Apparently, it tried to compute
the regression line after reading only one point, which is not enough to determine a line. We
suspect that this problem, then, is not in the computations but in the early exit from the input
loop.

The time-honored way to track down a bug like this is to put a printf() call after every
calculation, so that the problem code shows the state of the program at each significant step. If
the right things are printed at the right time, you can see where the application went off the
rails.

There is no need to instrument a step-by-step picture of Linrg's state, however, because we


have a computer to take care of that for us. The Xcode debugger will do everything we need.
3.2. Active Debugging
In our previous encounter with the debugger, it took control over Linrg when a fatal error
occurred. This time, we want the debugger to take control at a time of our choosing. By setting
a breakpoint at a particular line in Linrg, we tell the debugger to halt execution of the
application at that line, so that the contents of variables can be examined and execution
resumed under our control.

The easiest way to set a breakpoint is to click in the broad gutter area at the left margin of the
application source code in one of Xcode's editors. Select main.c in the Groups & Files list of the
main Project window to bring that file into the editing area. Scroll down to the first line of the
main() function if it isn't visible, and click in the gutter next to the line containing the command
n = 0 (Figure 3.1). On the screen, a long, dark-blue arrowhead appears in the gutter to show
that a breakpoint is set there. You can remove the breakpoint by dragging the arrowhead to
the side, out of the gutter; you can move the breakpoint by dragging it up or down the gutter.

Figure 3.1. Clicking in the gutter at the left margin of an editor area
to set a breakpoint at the adjacent line of code.

Clicking the breakpoint turns it pale gray and deactivates it without clearing it, which
is useful when more complex behaviors are attached to breakpoints. Control-clicking
the breakpointor right-clicking if you're using a two-button mousebrings up a menu
that allows you to remove, edit, or disable the breakpoint or to attach one of several
useful breakpoint actions. Breakpoint actions are discussed in Section 21.4.

SelectBuild and Debug from the Build and Go toolbar item in the main Project window, or
selectBuild and Debug (command-Y) from the Build menu. As before, Xcode performs any
tasks needed to bring the Linrg tool up-to-date, and starts running it. This time, however, the
Debugger window almost immediately shows that Linrg has halted at the breakpoint we set
(Figure 3.2).

Figure 3.2. The Debugger window as Linrg stops for a breakpoint at


the start of main(). The line at which execution paused is highlighted
in red on the sceen, and the current values of function arguments
and local variables are in the Value panel.

[View full size image]

Now we can take control. The top of the Debugger window consists of a toolbar (Figure 3.3)
that affords precise control over the execution of the program. The buttons and their actions
are as follows:

Build and Debug, available when the target application is not running, is a convenient
way to return to debugging after editing application source in the Debugger window's
editor pane.

Terminate halts the target application and ends debugging. When no program is
running, this button label is Debug and launches the current target under the debugger.

Fix allows you to make some changes in programs while they are running under the
Xcode debugger. This button compiles the file in the editor pane and attempts to patch
the file into the running process.

Restart halts the application being debugged and restarts it immediately under the
debugger. This saves time over terminating the application and restarting both the
debugger and the application.

Pause breaks execution of the target application wherever it happens to be.

Continue lets the target application continue running uninterrupted to the end or until it
encounters a breakpoint or an error condition.

Step Over lets the target application continue running until the next line in the function
currently executing, stepping over any function calls. If the current line is the last line of
the function, execution advances to the caller of the current function.

Step Into lets the target application run until the next line, whether it is in the current
function or in a function called in the current line. The debugger will step into function
calls.
Step Out lets the target application run until the current function returns.

Breakpoints opens a window listing all the breakpoints set in the current project. You
can add breakpoints by double-clicking in the label of the last, empty entry in the table
and typing the location for the new breakpoint.

Console opens a window that affords access to the command line features of the gdb
debugger, which underlies the Xcode debugger. This is the only way to access some
features of the debugger.

Figure 3.3. The toolbar of the Xcode Debugger window. The controls
in the toolbar allow you to start and pause execution of the program
being debugged or to step through the program line by line.
Specialized commands allow you to step into functions and methods
or to step out of the current function to its caller.

[View full size image]

Now we can step through Linrg one line at a time. To get a sense of this, scroll the variable
displayat the upper right of the Debugger windowdown so that the values of the sum...
variables are visible.

Now click the Step Over button a couple of times. The red highlight indicating the currently
executing line moves down the display of main.c in the Debugger window's editor; as you pass
the corresponding line, you see the values for sumX, sumY, and so on, change to 0.0. Whenever
an entry in the variable display changes in value, the new value is shown in red.

But wait. We see sumX,sumY, sumX2, and sumY2 get set to 0, but sumXY still displays in black the
junk value it had at the start. Did it get set? Will it? A quick examination of main.c in the editor
pane shows that we don't initialize sumXY. The line that should zero it out initializes sumY twice
instead.

Let's resolve to do something about that later. For now, we can force sumXY into good order by
double-clicking its value, typing 0.0, and pressing Return. The Xcode debugger and gdb, on
which it is based, allow you to set variable contents on the fly.

Another click of Step Over takes us to the line

int nScanned = scanf("%lg %lg", &x, &y);

We click Step Over at this line and find that Step Over is disabled. What's happening? This
line can't complete execution until the input of two floating-point numbers either succeeds or
fails. Awaiting input, scanf() blocks. To supply some, open the I/O log (Debug Standard
I/O Log), and again enter

1.0 2.05

PressReturn. The application is no longer blocked waiting for input; scanf() returns, and the
debugger can now honor our Step Over instruction by stopping at the next line.

Stepping slowly through the lines that follow, we see the progress of Linrg reflected in the
Another Random Scribd Document
with Unrelated Content
"He retains my hand too long when he helps me into a canoe.
The other day I was horribly tempted to tip him into the river; he
said such silly things and popped his eyes and went into rhapsodies
over my ankles—which was slightly infringing les convenances,
wasn't it?
"But he's merely a foolish, pompous, well-meaning man, slightly
silly about all women, but with a very kind heart, I fancy. He is
always doing things for me, always strutting around me and
shooting his cuffs and curling his mustaches. Half the time I don't
understand his talk—his jokes and apparently witty innuendoes,
which perhaps are very funny, for he laughs at them himself, and I
have to smile and pretend I am not stupid.
"No flight has occurred, although there was a white frost
Saturday night.
"The shooting brotherhood are anxious and gloomy. Some even
declare that a flight did occur Saturday night; that the birds
remained with us over Sunday, when nobody could shoot, and left
Sunday night, which was bitter cold and froze water in the garden.
"I don't know about such things—and don't care very much. It
seems to me that these big, red-faced men make a ridiculous to-do
about the migrations of a few small birds.
"Scott Wallace is the laziest man—which reminds me in time,
Jim, to speak about your apparent attitude toward Scott. I merely
wrote you that you would like him if you knew him.
"To my surprise, you wrote that you, personally, had no use for
the kind of man I described.
"Was that a snub for me or for Scott? I'm sorry I spoke of him.
To me he is a nice, wholesome, amusing fellow, so friendly to
everybody that, somehow, your letter—what you said in it about a
man you never met—hurt me. You would like him if you knew him.
So, with this feminine prerogative, I close my lips about Scott
Wallace for the present and the future.
"I am glad your arm is practically well; but what makes me
entirely contented is what you say of your constant and bewildering
promotions. Best of all is what I read between the lines—that you
really love the business—the business of generations of Edgertons;
and you, the last of them—but not the last, God willing!—are
plunging into the game up to your neck, interested, optimistic,
enthusiastic, fitting yourself for that dignified place which is yours,
Jim, by every right.
"Now that it's over, and the mist blown clear of your path
forever, I want to confess to you how dreadfully I felt to see you
here in such a capacity. More than that, your light talk about the
arts, your light and graceful accomplishments in them, your
tendency to drift back toward a career for which you are no more
fitted than I—all these things troubled me deeply, so that,
sometimes, I even dreamed of them, and finally came to regard your
facility with actual fear, so jealous was I for your real career, so
anxious was I that you should become your real self.
"I suppose you will scarcely believe it, Jim, when I tell you that
this feeling began from the very moment when you offered to go
with Silvette and me to Adriutha. Somehow, blindly, I understood
even then that it was not the thing for you to do; and, remember, I
knew you scarcely at all.
"Yet my instinct resented your going, and if I did not actually
protest, perhaps you may recollect that my attitude was not cordial;
that you had to ask me many times for my vote; that, after all, I
never cast it, but simply refrained from voting at all.
"I suppose this was cowardly in me; yet, Jim, what else could I
have done? I scarcely knew you; I dared not appear ungrateful after
your kindness to Silvette and to me.
"Forgive this self-defense. I merely wanted you to know; I only
wish you to understand that, at heart anyway, I have been, from the
beginning, loyal to the best interests of a friend and a kinsman who
was most kind to two girls alone in the world."

"This is a still, golden, autumn world—autumn no longer, alas! for


we are already well along in November. But autumn lingers in this
land of hills and waters, and the frost was not severe enough to
blacken the late roses. If the weather is unseasonable, it is also
charming, and I love it. Russet and gold always did fascinate me—
like the hangings and tapestries in your studio, with the dusty
sunlight falling over all.
"Eh bien, monsieur, I must conclude my monologue. You are a
brave man if you have read as far as the name you gave me once—
centuries ago.

"JAPONETTE."

She closed and sealed her letter, wrote his name on the envelope,
rested awhile, blue eyes seeing nothing; then, touching the envelope
with her lips, she laid it between the leaves of her portfolio.
Since that day in this very place, Edgerton had spoken no more
of love to her. She knew that he never would again, that what had
begun here on the Path to Yesterday had ended where the path
ended. Never again would he retrace those steps with her; never
again travel them alone. For it was a lost road to him, a blind trail
already overgrown with briars. The days made it fainter, the months
were hiding it, the years would obliterate it for him. But for her, alas
—she had many a pilgrimage yet to make along that briar-grown
path; and many a scar, yet unmade, must heal before that path
closed before her pilgrim feet, and shut out forever from her eyes
the hidden shrine it led to, where the sky was rosy above the river
and the starlings called through the golden light of Paradise.
And now, as she stood up, the subtle scent of autumn hung
heavy in the air—a faint odor of ripening, hinting of decay and
death. Summer had gone indeed—on earth and in her heart.
Never again would life be the same to her after this day, in this
place, alone with memory; never again would she be the same. How
old her heart had become—how old—how old! O amari dies! O
flebiles noctes!

She rode that afternoon with Colonel Curmew, accepting him instead
of another because she thought his chatter might leave her freer to
follow her own thoughts.
But after a while it seemed to her as though she could no
longer endure them, and that the colonel's inanities were preferable.
They were riding down a mountain road, the horses picking a
cautious way among the scattered stones.
He was paying court to her, as usual, and she had been riding
on, smiling absently, preoccupied with her own thoughts and
mentally oblivious to him, when there came a clatter of stones from
behind, and Scott Wallace galloped recklessly up at the risk of his
horse's neck as well as his own.
"Halloo!" he said cheerfully; "hope I'm not smashing a
twosome, colonel."
The colonel glanced sourly at him. Diana laughed with pleasure:
"Not at all, Scott! Colonel Curmew and I are old acquaintances, and
the resources of sentiment were long ago exhausted between us.
Where are you going?"
"Nowhere; I just felt like a gallop. All the chaps are kickin' over
the flight, which either isn't goin' to materialize or passed over
Sunday and made boobs of the bunch of us. Where are you goin'?"
"Nowhere in particular; come with us. My nerves needed
soothing, so I took the colonel along."
"As a tonic or quieter?" asked Wallace so seriously that Diana
threw back her pretty head and the woodlands were melodious.
The colonel laughed loudly, too, and began to hate young
Wallace with a hatred that passes all understanding.
Wallace turned to her. "What's wrong with your nerves? I
supposed you hadn't any."
"I didn't know it either, Scott. Probably I've played with cards
and cigarettes too hard. For all the sunshine, to-day has been a gray
one for me.... Shall we gallop?"
She launched her horse into a trot, a canter, then into a dead
run. Behind her tore the two men through the afternoon sunlight,
on, on, until their winded mounts topped the homeward crest of the
hill and they looked down on the meadows of Adriutha.
They wended their way down the mountain in silence—Diana,
grave and apparently tired; Wallace smiling slightly, and glancing at
her from moment to moment; Colonel Curmew pop-eyed,
expressionless, curling his mustache with gloved fingers.
He was furious with Diana, with Wallace, with himself. Yet even
he could not see how he might have resented the young man's
intrusion otherwise than by the lack of cordiality which he had
certainly manifested. Besides Diana had invited him to remain with
them. Of what low tricks women are capable! Because she knew
well enough that he had desired and sought a tête-à-tête.
Curling his mustache tighter, he rode on, a good figure in the
saddle always—ruminating, considering, angry because of the
interruption.
For Colonel Follis Curmew had for days, now, been carefully
preparing the way for something he meant to say to Diana. He was
a cautious man with women; he reconnoitered by degrees, inch by
inch, carefully watching effect. Hint, innuendo, double meanings, sly
feelers, veiled intent, was the strategy he usually employed at first,
skirmishing as close to the dead line as he dared; furtive, alert,
ready always for a brilliant and resistless climax at the psychological
moment.
A few minutes ago he had believed that the psychological
moment was approaching. He had said one or two things so cleverly
that not the least resentment had altered her smile; but how was he
to know that, if she had heard him at all, she had not in the least
understood him? It takes more than one to play a game of that kind.
The trouble was that her smiling inattention had deceived him—had
always deceived him. He was entirely persuaded that she had drifted
into the game long ago.
Surely, surely the psychological moment had been close at hand
when that big fool of a boy had come clattering downhill and
smashed their approaching understanding into smithereens for the
moment. The colonel silently damned him as he rode. It took time
and patience to gather up and piece together the fragments and
smithereens; it took skill and watchfulness to choose another such
propitious day and hour—to select the scenery and the moment for
what he meant to say to this young girl.
As he dismounted her at the foot of the terrace he pressed her
arm significantly, and said under his breath:
"Can we get away for a moment together this evening?"
Wallace was close by, and the colonel spoke so low and pinched
so discreetly that she neither understood nor noticed his amenities,
so she merely nodded smilingly, thanked him for his escort, and ran
up the steps beside Wallace.
"I'll be in the billiard room later, if that interests you," she called
back over her shoulder to Wallace as she ascended the stairs.
"It certainly does!" he replied promptly, and went away to
change.
Diana continued on to her own room, disturbing Jack and
Silvette on the stairs, and gaily jeering at them as she banged the
door. A curious reaction had set in from the sadness of the morning
—a feverish desire to escape from herself, from the misery that lay
always heavy in her breast, the relentless hours that weighted her
heart so that its dull beating had become a burden.
The bath refreshed her; so did the tea. She put on her little
Japanese gown and her straw sandals, and curled up by the window,
sipping her tea and watching the declining sun.
Dusk came swiftly, and with it Silvette who bent over and kissed
her, and tasted the tea, and wandered about the rooms gossiping,
too full of the joy of living to endure silence in herself or in anybody
else.
Pangs of swift remorse and self-reproach stabbed her at
intervals when she thought of her own happiness and remembered
Diana's late unhappy affair.
How far Diana had cured herself, she did not know, but she
knew that her sister was still more or less unhappy about Edgerton.
"Did you send him my note?" she inquired.
"Yes: I wrote him, and inclosed it."
"He's a dear boy.... How well he must be doing! He ought to go
down on his knees and thank you every day of his life for what he is
turning out to be."
"He would have turned out all right anyway, sooner or later."
"Well, he's a horrid pig if he isn't grateful to you.... I don't
suppose he has the slightest idea what his regeneration cost you."
"Don't talk that way, Silvie."
"What way? I'm merely saying——"
"Don't say it, dear.... If it cost me anything, he is never going to
know it."
Silvette looked at her wistfully. "If I could only see you as happy
as I am, Di.... Sometimes I can scarcely bear to be as happy as I
am, and remember that you are not sharing it."
"True," said Diana, smiling; "Jack can't marry us both, so we
can't share your happiness, dear."
Silvette came and sat on the arm of the chair, drawing one arm
about Diana's neck.
"Do you still care for him very much?" she asked sorrowfully.
"Very much."
"Do you think it will last?"
"Yes."
"What are you going to do?"
"Nothing."
"Isn't there something to do?"
"Nothing."
"Perhaps, all this time he really cares for you."
"There is not the slightest possibility. I had my chance; he cared
for me—at that moment—when he told me so.... Those men out
there"—she made a vague gesture toward the unseen hills—"are no
more deadly cool when they shoot than was I when I deliberately
killed in him whatever love he may have had for me.... I slew it, I
tell you. There is no resurrection for dead things."
Silvette sighed heavily, and laid her smooth cheek against her
sister's hair.
"Still," she murmured half to herself, "there are miracles."
"There were."
"There may be others yet."
"No; I wounded his pride."
"You aroused it."
"By wounding it, and at the expense of what fell dead beside it.
Love died that day, little sister, and for that death there is no
reincarnation."
Again the feverish desire for escape came over her, seeming to
burn through every vein, and she sprang to her feet and rang for the
maid.
"I'm likely to do almost anything to-night," she said. "Shall I
make it a double event when you're ready?"
"A double—what?"
"Double event—double wedding? I can easily do so. Is it a good
way to drown your griefs, Silvie? Because the prospect of being
alone after you and Jack marry actually terrifies me."
"You little goose, you'll live with us!"
"I see myself doing it!—the superfluous spinster to be reckoned
with, counted in at dinners, mollified by kindness, secretly feared for
her acidulated tongue, to be employed later in either bribing or
disciplining the children."
"Di!"
"What?"
"If—in the—the——"
"Course of human events——"
"Jack and I have children," continued Silvette, flushing, "we'll
also have nurses to look out for the grubby little things."
"Grubby! You don't know what you're saying. You'll be the most
adoring—and adorable mother——"
"Well, please don't talk about it.... I don't care for children
now.... I don't know how I'll feel later."
Diana stood in the middle of the room—the smile fading from
her face, her small hands clenching.
"I've learned to like children," she said. "I've learned to love
them, somehow—even babies.... I want one of my own," she added
fiercely. "I wish for one very much; and if I can't have one—and it's
impossible, of course—I—I'll marry some man and have one!"
"Good heavens!" exclaimed Silvette, horrified, "what are you
talking about? I'll let you have one of mine!"
"I don't want yours! How do you know you'll have any? How do
you know you'll have more than one?"
Her eyebrows were bent inward, her lips compressed; she
turned her head and stared out at the stars—from where, they say,
all babies come, and where they all return at last.
"You know," she said calmly, "that I wouldn't really do such a
thing—even to have what I care for so much.... And yet—if a woman
is tired, hopeless, alone, isn't marrying some man a help to her?
Can't she stand the passing years better? Doesn't it give her some
respite from the eternal pain—here"—she laid a slim hand on her
breast—"doesn't it give her something to live for, especially if
children should come? I don't know, Silvie; I ask you because I'm
tired and confused with the pain of it."
"My darling!"
She dropped her head on Silvette's shoulder for a moment;
then, as the maid knocked, lifted it calmly and bade her come in.

That night at dinner she was very gay—a charming, sparkling,


bewildering creature. Through and through Colonel Curmew shot
intermittent pangs of jealousy and doubt, mercifully assuaged by
hope; through and through Scott Wallace her blue eyes seemed to
penetrate, exposing to her laughing gaze his youthful and very
susceptible heart.
"That night at dinner she was very gay—a charming,
sparkling, bewildering creature."

"Certainly I'm bowled over," he admitted cheerfully to himself.


"She is the cunnin'est thing that ever missed a pheasant; but she's
found me, all right, with both barrels, and the sky's full of feathers,
and I'm on the sod, kickin'."
Me managed to tell her so that evening, in language
sportsmanlike and picturesque, before they cut for partners at
auction. She was standing on the stairs, two steps up; he below her,
with his handsome face lifted.
"All you've got to do is to send your dogs forward, and retrieve
me, Diana. I'm grassed in the open in plain sight."
"Suppose I should take you up, Scott?"
"Is it a go?"
She smiled down at him.
"Take care, young man. I'm approaching spinsterhood at a
terrifying speed. How do you know that I may not clutch wildly at
you?"
"For Heaven's sake, clutch!" he urged her.
"How? Shall I roll up my eyes and whisper, 'Oh, Scott!'—or shall
I take a flying leap at you from here, and rope you before you can
get away? Instruct me, please, because I really don't know as much
about such customs as perhaps you think I do."
"Take the flyer, Diana; I'll catch you. Are you ready? Come on;
be a sport!"
"I can't be a sport, Scott. I try; I make a brave effort to be
cigaretteful and naughty, but—I'm ashamed to say it isn't in me.
Now you'll run, I suppose."
"After you—yes.... Diana, I do love you. I haven't said it right,
that's all. Will you marry me and make somethin' out of me besides
a loafin' lout in puttees?"
"Oh, Scott, you're so beautiful in puttees! I wouldn't make
anything else out of you if I could; you must be perfectly gorgeous
in pink."
"Come down to the next hunt ball and see. They're a fine bunch
at Meadowbrook. You'll like 'em; maybe you'll learn to like me."
"I do now, you scatter-brain! I adore you, Scott; but, you know,
love is a different game."
"That'll come all right," he protested. "When you're the missus,
and you see me come a cropper over five bars, you'll suddenly wake
up to find you love hubby. And I won't be hurt, but you'll think I am,
and you'll pull up and scramble down and look me over, and cover
my pale and beautiful face with kisses and—I'll play foxy and let
you," he ended with pleased satisfaction.
The smile on her face had suddenly become fixed: for what he
was saying had conjured up a vision of the polo field, and a young
fellow in white picking himself up from the trampled sod.
Wallace, looking around to see that the hall was empty, sprang
up the two steps and took her hand in his.
"Diana, I do love you dearly," he said. "Will you take me on for
a trial gallop?"
"Do you mean an engagement?" she said, looking him over.
"Yes, I do; will you?"
"What kind of an engagement?"
"The regular—with a sparkler on the side. Will you, Di?"
"No, you very slangy young man, I won't."
"Well, then—then—what kind of an engagement do you
suggest?" he asked cheerfully. "Just the circingle and halter kind?"
"What kind is that, Scott?"
"Oh, an understanding that you're not bitted and bridled yet."
"You mean that the engagement lasts during my pleasure?"
"Yes, that's it."
"And ends in marriage—or a very, very kind note?" she asked,
laughing.
"Sure thing! Am I on?"
She considered him, smilingly.
"If you like," she said.
"Oh, I do like! It's awf'lly good of you, Diana.... Would you be
gracious enough to wear a sparkler?"
"Not yet, Scott."
"Oh, that's all right—whenever you say." He looked up at her,
blushing. "Do you mind if I kiss you?"
She looked at him for a second, then impulsively bent forward
and kissed him squarely.
"You nice boy," she said gently; "you nice, nice boy. I wish the
world were fuller of your sort.... I don't love you, Scott.... I don't
suppose I shall.... But if you knew what I feel for you, I believe you
wouldn't exchange it for any love I could ever give you.... Shall we
go into the billiard room? I'm playing at Colonel Curmew's table, and
he's probably perfectly furious at being kept waiting."
She gave his hand a friendly pressure as he released it,
laughed, blushed, and turned away toward the billiard room, where
the clamor was already audible.
They parted at the door, where she met her sister in
conversation with Mr. Rivett.
"Diana," she said, "Mr. Rivett and I are going to town on the
early train. You know he goes every week, and I've simply got to do
some shopping. Will you come with us?"
Diana's heart gave a bound. To her, New York had become
merely the abiding place of Edgerton, and every mention of it
started her pulses.
"Oh, do come, Di," urged her sister. "If you'll come, we'll have
Jim to dinner at the Plaza. All the theaters are open, too, and we can
have a jolly time."
"How on earth is Jack going to bear it?" asked Diana, laughing.
"Bear it? Did you suppose Jack wasn't coming?" asked Silvette
so naïvely that the corners of Mr. Rivett's eyes cracked into wrinkles.
"All right, I'll come," said Diana, with never a thought for Scott
Wallace; but, thinking of Edgerton, she had meant to go from the
first.
As Silvette, on her future father-in-law's arm, walked on toward
the drawing-room, Colonel Curmew appeared from the billiard room.
"Oh," said Diana, "I am so sorry to have kept you waiting. I was
talking to my sister about going to town to-morrow."
"I want to see you before you go," said Curmew in a low voice.
"It can't be done now—they're waiting for us, and Mrs. Wemyss is
developing a temper. When can I see you?"
"Why, I don't know," she said, smiling. "What have you to say to
me that cannot be said now?"
The colonel's eyes popped, and he leered at her, not doubting
her coquetry.
"On the terrace after cards," he said, curling his mustache. "Is
that understood?"
"Indeed, it is not, Colonel Curmew!" she said, amused. "I shall
retire early, because I have an early train to catch."
The colonel's face darkened. There were limits to coquetry.
"When did you decide to go?"
"A few minutes ago."
"You knew I had something to say to you?"
"I knew nothing of the sort. And what has it to do with my
going to town, anyway?"
The colonel had only a few moments to decide.
"How long will you be in town?"
"I don't know."
"Where will you be?"
He wearied her, and to be rid of him she thoughtlessly gave him
the address at the Plaza.
"I'll be in town for a day or two," he said, leering at her once
more.
If she heard, she paid no heed, for she was already entering the
billiard room with a gay gesture and a smile for Wallace, who waved
his hand in reply, and looked volumes at her across the hubbub.

CHAPTER XIV
DESUNT CÆTERA

Silvette and Diana, in one of Mr. Rivett's town limousines, had


shopped to their hearts' satisfaction, inspected fashions for the
coming winter in hats and furs and gowns and various intimate
affairs of flimsier fabric, had whirled away down town to lunch with
Mr. Rivett and Mr. Dineen at the Iron and Steel Club, then whirled up
town again to resume the delicious exploration of those glittering
Fifth Avenue shops which line that thoroughfare from Madison
Square to the gilded battle horse and its rider in two almost
unbroken ranks.
In that magic land, where trousseaux are assembled and
garnered by pretty brides to be, Silvette lingered, fascinated; but her
rapid, intelligent survey was only preliminary as yet. She and Diana
were merely en vidette; official inspection and an advance in force
would follow later.
But, oh, the jewels and the furs and the lovely laces and the
heavenly hats!
Every shop was now in full swing toward the culminating,
scintillating transformation of Christmas; the avenue was crowded
with flashing automobiles and carriages, the florists' windows were
beautiful, the sidewalks crowded.
Men sold violets everywhere at street corners or offered
enormous, orange-tinted chrysanthemums nodding on long stems;
giant policemen on foot kept busy ward at every crossing; superb
mounted police calmly stemmed the twin torrents and, with lifted
hand, quieted the maelstrom. Far to the south, in snowy
magnificence against the sky, the huge marble tower brooded under
its golden lantern above the city's roar; northward the naked trees of
the park turned ruddy and golden in the eye of the level sun.
And all of it the two young girls beheld, and part of it they were
—sometimes afoot in the throng, sometimes in their limousine,
looking out with enchanted eyes upon all this magic—magic only,
alas! to the unspoiled eyes of youth.
From time to time Silvette had stopped at any convenient place
to telephone Edgerton, calling him up at his various points of
possible contact. She had telegraphed him the morning that they left
Adriutha, which was the day before, but, as time passed, it became
evident that he had not yet received the telegram.
Some days ago he had gone to Pittsburg at Mr. Dineen's
suggestion. On his way back he was to stop at Philadelphia and
Jersey City.
Rivett said at luncheon that he'd probably return to his rooms
before dining, and find their telegram in time to join them at the
Plaza for dinner.
But he didn't come, nor did any word arrive from him; and
Silvette and Jack went off to the New Theater to see "The
Thunderbolt" matchlessly staged and acted in a matchless theater;
and Rivett offered to take Diana anywhere.
But the girl was sick at heart under her smiling, feverish gayety,
and the brilliant darkness of the streets seemed to mock her as she
looked out into them.
Also, there was a chance that Edgerton might arrive late and
telephone to somebody—perhaps even to her.
It was merely a chance, but her chances were few these days,
and she durst not pass one by, no matter how unlikely it looked.
So she thanked Mr. Rivett, and preferred her room in the pretty
suite to which he had invited Silvette and herself; and there she sat
in her silken dinner gown, sunk into the velvety depths of a chair,
watching the city lights from the window, waiting, listening—always
listening with a hope that died and lived with her unquiet breathing;
fading, flowering, waxing, waning, dead and alive between two
heartbeats—the hope forever new—the only living thing which
cannot die while the sad world endures.
Below her, far below, the lights of motors ran swiftly like passing
meteors; the lights of carriages and hansoms streamed to and fro,
yellower and slower; the lighted windows of street cars glided across
her line of vision in endless, level repetition.
To the west the gemmed façade of the New Theater sparkled
above the trees; northward the lighted streets spread away like
linked jewels under the winter stars.
Into the high silence where she lay and looked out into the
night, only a faint rumor of the city mounted from below; a tongue
of flame rustled on the hearth; the clock ticked.
Suddenly, silence was shattered in her ears; she sprang to her
feet, one hand against her heart, her stunned senses deafened by
the clamor of the telephone.
The next instant she was at the receiver—the receiver pressed
convulsively to her ear.
"Yes," she said faintly.
* * * * * *
"Yes; this is Miss Tennant."
* * * * * *
"Yes—Diana Tennant. Who is it?"
* * * * * *
"Yes; I will hold the wire."
She rested against the shelf, relaxing from the tension; then,
rigid, electrified:
"Yes! Is that you, Jim?"
"Of course!" he replied. "Are you at the Plaza?"
"Yes—all alone. Oh, Jim! I am so glad to hear your voice!"
"It's bully of you to say it. I'm delighted to hear yours. I have
just come in and found Silvette's telegram on my desk. Shall I come
around?"
"Will you?"
She could hear him laughing, then:
"Watch me," he said, "if the dust doesn't obscure the spectacle,
I'll be with you in five minutes. Is that right, Diana?"
"It is perfectly right."
As though dazed she hung up the receiver in its nickel
wishbone, and began walking aimlessly up and down the room
trying to collect her wits and calm her senses. Outwardly composed,
inwardly facing chaos, she threw open the window and turned her
face to the coolness of the winter stars.
Then behind her the telephone sounded again. It was only the
announcement of his arrival, and she closed the door of her room
and went into the pretty parlor, where a maid was already turning on
the electric lights.
His ring sounded; the maid admitted him to the outer hall, took
his hat and coat, and ushered him in. Diana rose to receive him with
smiling composure as the maid retired to the bedroom.
"This is very prompt of you, Jim—-and promptness is the most
subtle of flatteries.... How thin and white you look! ... Are you
perfectly well?"
"Perfectly. I need not ask that question of you, Rose of the
Berkshires!"
"Do I really look well?"
"Flawless and dewy fresh—a trifle slim, perhaps. Don't they
keep you in pheasants?"
"They do, kind sir. It's fashion, not slenderness, you behold.
Never mind how it's accomplished. But, Jim, you don't look well. Are
they working you to death?"
"Not so you'd notice my decease," he said laughingly. "I'm in
the game, up to the neck, and swimming strongly. It's a fine game,
Diana. No doubt generations of Edgertons on high look down on me
and sing in unison the Anvil Chorus. It's a great game—this iron one.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like