SlideShare a Scribd company logo
Get the full ebook with Bonus Features for a Better Reading Experience on ebookgate.com
Learning the iOS 4 SDK for JavaScript Programmers
Create Native Apps with Objective C and Xcode 1st
Edition Goodman
https://ebookgate.com/product/learning-the-ios-4-sdk-for-
javascript-programmers-create-native-apps-with-objective-c-
and-xcode-1st-edition-goodman/
OR CLICK HERE
DOWLOAD NOW
Download more ebook instantly today at https://ebookgate.com
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...
Learning the iPhone SDK for JavaScript Programmers Create
Native Apps with Objective C and Xcode 1st Edition Danny
Goodman
https://ebookgate.com/product/learning-the-iphone-sdk-for-javascript-
programmers-create-native-apps-with-objective-c-and-xcode-1st-edition-
danny-goodman/
ebookgate.com
iOS 12 App Development Essentials Learn to Develop iOS 12
Apps with Xcode 10 and Swift 4 Neil Smyth
https://ebookgate.com/product/ios-12-app-development-essentials-learn-
to-develop-ios-12-apps-with-xcode-10-and-swift-4-neil-smyth/
ebookgate.com
iOS 9 SDK Development Creating iPhone and iPad Apps with
Swift 1st Edition Adamson
https://ebookgate.com/product/ios-9-sdk-development-creating-iphone-
and-ipad-apps-with-swift-1st-edition-adamson/
ebookgate.com
Beginning IOS Storyboarding with Xcode Lewis
https://ebookgate.com/product/beginning-ios-storyboarding-with-xcode-
lewis/
ebookgate.com
Pro Objective C Design Patterns for IOS 1st Edition Carlo
Chung
https://ebookgate.com/product/pro-objective-c-design-patterns-for-
ios-1st-edition-carlo-chung/
ebookgate.com
Learning Cocoa with Objective C 4th Edition Paris
Buttfield-Addison
https://ebookgate.com/product/learning-cocoa-with-objective-c-4th-
edition-paris-buttfield-addison/
ebookgate.com
JavaScript for Programmers 1st Edition Paul J. Deitel
https://ebookgate.com/product/javascript-for-programmers-1st-edition-
paul-j-deitel/
ebookgate.com
Learn Unity 4 for iOS Game Development Create amazing 3D
games for iPhone and iPad 1st Edition Philip Chu
https://ebookgate.com/product/learn-unity-4-for-ios-game-development-
create-amazing-3d-games-for-iphone-and-ipad-1st-edition-philip-chu/
ebookgate.com
Learning Mobile App Development A Hands on Guide to
Building Apps with iOS and Android 1st Edition Jakob
Iversen
https://ebookgate.com/product/learning-mobile-app-development-a-hands-
on-guide-to-building-apps-with-ios-and-android-1st-edition-jakob-
iversen/
ebookgate.com
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
Learning the iOS 4 SDK for
JavaScript Programmers
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
Learning the iOS 4 SDK for
JavaScript Programmers
Danny Goodman
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
Learning the iOS 4 SDK for JavaScript Programmers
by Danny Goodman
Copyright © 2011 Danny Goodman. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Editors: Andy Oram and Brian Jepson
Production Editor: Holly Bauer
Copyeditor: Amy Thomson
Proofreader: Kiel Van Horn
Indexer: Ellen Troutman Zaig
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Printing History:
December 2010: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Learning the iOS 4 SDK for JavaScript Programmers, the image of a King Charles
Spaniel, and related trade dress are trademarks of O’Reilly Media, Inc.
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 O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-38845-4
[LSI]
1291233444
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. Why Go Native? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Using an App Offline 2
More Access to the Hardware 3
More Access to the Software 4
What You Lose 6
Distribution 7
Apple iOS Developer Program 8
Content 8
Authoring Platform Choices 8
Taking the Plunge 9
2. Welcome to the iOS SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Hardware and OS Requirements 11
Installing the SDK 12
About iOS Developer Programs 12
Inside the SDK 14
Viewing Developer Documentation 15
Loading Code Samples 18
Setting the Project’s Base SDK 21
Trying the iOS Simulator 22
Coming Up... 24
3. Creating a Test Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Creating the Project in Xcode 26
Selecting a Project Type 26
Naming and Saving the New Project 29
Welcome to Your Project 29
Editing Your First Files 31
What the runMyCode: Method Does 34
v
Building the User Interface 35
Adding a Button to the View 38
Connecting the Button 42
Going for a Test Ride 46
Congratulations 49
4. Structural Overview of an iOS App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Where It All Begins: APIs 51
APIs You Already Know 51
The Cocoa Touch APIs 52
Frameworks 53
Foundation Framework 54
UIKit Framework 54
CoreGraphics Framework 55
Adding Frameworks 55
Frameworks Set in Stone 56
Welcome to Class Files 57
The JavaScript Way 57
The Objective-C Way 58
Header File Details 61
Using Xcode to Create DGCar Class Files 65
Editing the @interface Section 68
Message Passing 70
Editing the @implementation Section 70
Integrating the DGCar Class into Workbench 75
Creating Object Instances 76
NSLog() and String Formats 77
Running the Code 78
What About Accessing Instance Variables? 79
Recap 81
5. App Execution Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Some C Language Roots in an iOS App 83
An Introduction to Delegates 85
How UIApplication Appoints Its Delegate 87
The App’s Info.plist File 87
Inside MainWindow.xib 88
iPhone App Development Design Patterns 92
The Model-View-Controller Design Pattern 92
Other Design Patterns 94
The Importance of Views 95
The App Window—UIWindow 96
Adding Another View to Workbench 97
vi | Table of Contents
Recap 106
6. Central Objective-C Concepts: Pointers, Data Types, and Memory Management . .
107
Pointers 108
Pointers and Memory 108
Pointers and Objective-C Variables 110
Pointer Notation 111
Determining Pointer Usage 113
Data Typing 115
Objective-C Data Types 116
Cocoa Touch Data Types 116
Objective-C Variable Declarations 118
Objective-C Method Declarations 118
The id Data Type 122
Converting Objective-C Data Types 123
Memory Management 125
Cleaning Up After Yourself 125
The Retain Count 127
Autorelease Pools 129
Observing Memory Usage 130
Recap 131
7. C Language Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Variable Names 133
Variable Scope 136
Instance Variables 137
Local Variables 137
Local Variables in Control Structure Blocks 138
Static Local Variables 140
Global Variables 140
Constant Values 141
Functions 142
C Structures 148
C Arrays 151
Enumerated Types 152
Operators 153
Program Flow Constructions 153
Boolean Values 154
Math Object Equivalents in C 155
Inserting Comments 157
Recap 157
Table of Contents | vii
8. Objective-C/Cocoa Touch Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
More About Classes 159
Temporary Objects 160
Subclassing Framework Classes 161
Defining Your Own Custom Subclasses 162
Adding to a Class Without Subclassing—Categories 166
Real Classes in Real Action 168
TheElements Overview 168
TheElements Class File Structure 171
Class Properties 175
Specifying Properties in the Header File 176
Synthesizing Properties in the Implementation File 178
Using Properties 178
Properties in Framework Classes 180
About NSString 181
Creating an NSString 182
JavaScript String Method Equivalents in Objective-C 185
NSMutableString 189
About NSArray 190
Creating an NSArray 192
Retrieving Array Elements 193
JavaScript Array Method Equivalents in Objective-C 193
NSMutableArray 194
About NSDictionary 195
Creating an NSDictionary 195
Retrieving Dictionary Entries 197
NSMutableDictionary 198
Arrays and Dictionaries in Action 199
Recap 202
9. Common JavaScript Tasks in Cocoa Touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Formatting Numbers for Display 203
Preformatted Number Styles 204
Rounding Numbers for Display 206
Creating a Date Object 207
Adding a UIDatePicker to Workbench 207
Understanding NSDate 210
Creating a Date Object for a Specific Date 211
Extracting Components from an NSDate Object 213
Creating NSDate Objects from Strings 214
Converting an NSDate to a String 217
Calculating Dates 219
10 Days in the Future 219
viii | Table of Contents
Days Between Dates 220
Comparing Dates 221
Downloading Remote Files Asynchronously 222
Example Project 223
Creating the Request 224
Initializing the NSMutableData Object 225
Delegate Methods 226
Downloading Only When Needed 228
Accounting for Fast App Switching 231
Reading and Writing Local Files 233
iOS App Directories 233
Obtaining Directory Paths 235
Obtaining Paths to Files Delivered with Your App 236
Writing Files to Disk 236
Reading Files from Disk 238
Writing and Reading Property List Files 239
Performing File Management Tasks 240
Sorting Arrays 241
Sorting with a Selector 241
Sorting with a Function 243
Sorting Arrays of Dictionaries with NSSortDescriptor 245
Capturing User-Entered Text 246
The Code Portion 247
The Interface Builder Portion 250
Validating Text Entry with Regular Expressions 251
Modifying the Code 253
Modifying the User Interface 255
Using Regular Expressions for Text Search and Replace 255
Dragging a View Around the Screen 258
The Code Portion 259
The Interface Builder Portion 264
Recap 265
A. Getting the Most from Xcode Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
B. Common Beginner Xcode Compiler Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Table of Contents | ix
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
Preface
You don’t have to be an Apple fanboy or fangirl to give Apple Inc. credit for redefining
mobile gadgetry and its surrounding industries. First the company used the iPod to
reshape the music industry and strongly influence how we acquire and consume tunes.
Just count the number of people wearing iPod-connected earbuds in a subway car.
Then the iPhone rewrote the cellular telephone industry manual, while opening the
world’s eyes to the potential of being connected to the Internet nearly everywhere, all
the time. It’s happening again with the iPad, where electronic publishing is evolving
right before our eyes.
Although the iPhone was an early success with just the workable but limited set of
Apple-supplied applications that came with the phone, programmers couldn’t wait to
get their hands on the platform. The first word that Apple let drop about third-party
developers, however, landed with a bit of a thud: they were graciously allowed to create
web apps. Sure, the iPhone’s WebKit-based browser let creative HTML, CSS, and
JavaScript programmers create far more than dull web pages, but the apps still faced
frustrating limits compared to Apple’s native apps.
It took some additional months, but Apple eventually released a genuine software
development kit (SDK) to allow third-party programmers to create native applications
for what was then called the iPhone OS. Part of Apple’s task was also creating the App
Store to distribute apps—yet another industry-transforming effort. Many existing Mac
OS X developers rejoiced because the iPhone OS was derived from Mac OS X. The
iPhone SDK was based on the same Xcode tools that Mac developers had been using
for some time. The language of choice was Objective-C.
As a happy iPhone early adopter, I eagerly awaited the iPhone SDK. Unfortunately,
despite my years of being a dedicated Mac user since 1984 and a scripter since 1987
and the HyperCard days, I had never done any Mac OS X programming. I didn’t know
much about C and next to nothing about Objective-C. Still, I thought perhaps my years
of experience in JavaScript would be of some help. After all, at one time I even learned
enough Java to write a small browser applet to demonstrate how JavaScript code in a
web page can communicate with the applet. At least I knew what a compiler did.
xi
When the iPhone SDK landed on my Mac, I was simply overwhelmed. The old meta-
phor of trying to sip from a firehose definitely applied. The more I read Apple’s early
developer documentation, the more I felt as though I had to know a lot more than I
knew just to understand the “getting started” texts. With JavaScript having been the
most recent language acquisition for me (albeit back in late 1995), I looked for anything
I could borrow from that experience to apply to iPhone app development. I’d see
occasional glimmers, but I was basically flying blind, not knowing what I had to discard
and what I could keep.
The SDK was evolving during that time as well. I’d read a tutorial here and there, but
I wasn’t making much headway at first. Some tools, especially Interface Builder, felt
incomplete to me. Frankly, I had a couple of false starts where I walked away until a
future SDK version appeared. Finally, I reached a point that was “put up or shut up.”
After sticking with it and reading many of the documents many times, I was, indeed,
getting tastes from the firehose. Working on iPhone development as a part-time effort
over a three-month period, I managed to go from the starting line to submitting my
first app to the App Store in January 2009.
Since then I’ve been monitoring the developer communities on both the native app and
web app sides. I’ve even sat in online courses for web app developers to see what they’re
saying in the chat room. A lot of web app developers seem to look enviously to native
iPhone and iPad development. I suspect many have gone through the same false starts
that I did. And yet I know from my own experience that it is possible to make the
transition from web app to native app developer if you know how to channel your
JavaScript knowledge into what is now known as the iOS SDK environment.
What You Need to Start
I have written this book specifically for the web developer who is comfortable in the
JavaScript language. Even if you use a bit of JavaScript to glue together apps from third-
party JavaScript libraries and frameworks, you should be ready for this book. Unlike
most entry-level iOS programming books, this one assumes that you have not neces-
sarily worked in a compiled language before. You probably have little or no experience
with C or Objective-C. But you do know what a string and an array are because you
use them in your JavaScript work. I will be introducing you to the way Objective-C
works by comparing and contrasting what you use in JavaScript. It’s the kind of hand-
holding that I wish I had when I started learning iPhone app development.
You will get more from this book if you are the adventurous type. By adventurous, I
mean that you will follow the instructions throughout to try things for yourself. Along
the way I will help you build an app called Workbench, where you will be able to play
and learn by experimenting with little pieces of code here and there. Creating projects,
editing files, and building apps is the only way to really get to know the SDK.
xii | Preface
Of course, you’ll need a Macintosh running Mac OS X version 10.6 (Snow Leopard)
or later. I’ll have more details about getting set up with hardware and SDK software in
Chapter 2.
What’s in This Book
Perhaps because my programming knowledge has been completely self-taught over the
decades, this book does not follow what some might term traditional programming
languagetraining.Firstofall,youalreadycometothebookwithspecializedknowledge.
The goal of the book is to pick up where that knowledge leaves off and fill in the gaps
with the new material. There’s no doubt about it: there is a lot of new material for you.
But I have tried to establish a learning progression that will make sense and keep you
interested while you learn the decidedly unglamorous—but essential—parts of iOS
programming.
Chapter 1 goes into detail about the differences between web app and native app pro-
gramming for devices running iOS. It’s not all roses for native app development, as
you’ll see, but I believe the positives outweigh the negatives. In Chapter 2, you will
install the iOS SDK, inspect one of the sample apps, and run it on the iOS Simulator.
Then in Chapter 3, I put you to work to create your first iPhone app—the Workbench
app that you’ll use throughout the rest of the book. The steps are intended to help you
get more comfortable with Xcode and learn what it’s like to work on an app in the
environment.
In Chapter 4, you will use the Workbench app to build your first Objective-C object
and compare the process against building the same object in JavaScript. You will spend
a lot of time in Xcode. And if you’ve used JavaScript frameworks for your web app
development, wait until you get a peek at the frameworks you’ll be using in iOS
app development.
The focus of Chapter 5 is understanding how the code you write commands an iOS
device to launch your app and get it ready for a user to work with. In the process, you’ll
learn a great deal about how an app works. In fact, by the end of this chapter, you will
add a second screen to Workbench and animatedly switch between the two.
Sometimes while learning new material, you have to take your medicine. That happens
in Chapter 6, where you meet three programming concepts that are foreign to what
you know from JavaScript: pointers, data typing, and memory management. There
will be plenty of sample code for you to try in the Workbench app to learn these new
concepts.
Objective-C is built atop the C language. There is still a bit of C that you should know
to be more comfortable in the newer language. Chapter 7 shows you what you need to
know from C. The good news is that a fair amount of it is identical to JavaScript.
Hooray! And most of the esoterica isn’t needed because it’s all covered in more robust
Preface | xiii
and friendly ways in Objective-C, as covered in Chapter 8. There you’ll learn how
Objective-C handles strings, arrays, and other data collections.
The final chapter, Chapter 9, is also the longest. It provides a catalog of programming
tasks you’re accustomed to, but implemented in the iOS SDK. Most of the jobs will be
familiar to you—formatting numbers, performing date calculations, sorting arrays,
working with user-entered text, having Ajax-like communications with a server, and
even dragging an item around a screen. I don’t expect you to learn and remember
everything described in Chapter 9, but know what’s there and how to find it when the
need arises in your own iOS development.
Two appendixes round out the offering. One provides tips on using the iOS SDK’s
documentation to its fullest extent. The other presents a list of common Xcode compiler
errors that beginners encounter and what the errors really mean. Unintelligible error
messages in the early going of learning a new environment can be very frustrating
and discouraging. Appendix B makes it possible to learn more quickly from newbie
mistakes.
Conventions Used in This Book
The following typographical conventions are used in this book:
Plain text
Indicates menu titles, menu options, menu buttons, and keys.
Italic
Indicates new terms, URLs, email addresses, filenames, file extensions, and direc-
tories.
Constant width
Indicates variables, methods, types, classes, properties, parameters, values,
objects, XML tags, the contents of files, and logging output.
Constant width bold
Highlights new code or code of special importance in examples.
Constant width italic
Shows text that should be replaced with user-supplied values.
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
xiv | Preface
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example code
from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title,
author, publisher, and ISBN. For example: “Learning the iOS 4 SDK for JavaScript
Programmers by Danny Goodman (O’Reilly). Copyright 2011 Danny Goodman,
9781449388454.”
If you feel your use of code examples falls outside fair use or the permission given above,
feel free to contact us at permissions@oreilly.com.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/9781449388454
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
Preface | xv
Safari® Books Online
Safari Books Online is an on-demand digital library that lets you easily
search over 7,500 technology and creative reference books and videos to
find the answers you need quickly.
Withasubscription,youcanreadanypageandwatchanyvideofromourlibraryonline.
Read books on your cell phone and mobile devices. Access new titles before they are
available for print, and get exclusive access to manuscripts in development and post
feedback for the authors. Copy and paste code samples, organize your favorites, down-
load chapters, bookmark key sections, create notes, print out pages, and benefit from
tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full
digital access to this book and others on similar topics from O’Reilly and other pub-
lishers, sign up for free at http://my.safaribooksonline.com.
Acknowledgments
Having published over 45 books since the early 1980s, I have witnessed many changes
across the computer-book universe. But one beacon of quality has always burned
brightly: O’Reilly. The opportunity to publish a title through O’Reilly inspires an
author to produce a work commensurate with an impeccable publishing record. It was
a comfort to have super-knowledgeable editors Brian Jepson and Andy Oram chal-
lenging me to compose a better book at every step. Technical reviewers Alasdair Allan
and Zachary Kessin responded above and beyond the call of duty to make sure my facts
were factual and the reader’s best interests were being served.
xvi | Preface
CHAPTER 1
Why Go Native?
Those who frequently develop mobile web applications with HTML, CSS, JavaScript,
and related technologies tend to find a way to reuse those comfortable tools for every
app challenge. The iOS (formerly iPhone OS) platform has attracted much attention
in the web developer community, and Apple continues to evangelize web app devel-
opment for the platform.
At the same time, there’s evidence of a desire among developers to adapt their web
technologies to replicate the look and feel of native iPhone and iPad apps, whose look
and feel users know from the built-in apps and other apps downloaded from the App
Store. Perhaps you’ve used third-party libraries, such as iUi or jQTouch, to deploy your
content and application ideas so that they look and behave like native iOS apps.
Despite advances in web technologies—especially the HTML5 and WebKit extensions
to CSS and Document Object Model (DOM)—an iPhone or iPad web app lacks access
to several key facilities built into iOS. You must also deal with the Mobile Safari browser
address bar, especially if your users aren’t experienced enough to generate a home
screen icon for your app. Additionally, even though both your iPhone-specific styles
and scripts target a single OS platform, you still may encounter compatibility issues
with earlier versions of Mobile Safari running on iPhone and iPod touch units in the
field that haven’t been updated to the latest OS versions. For example, I saw from my
server logs that nine months after the release of iPhone OS 3.0, some users of my native
iPhone apps continued to use iPhone OS 2.2, especially with iPod touch devices (most
of whose users once had to pay for major OS upgrades).
In other words, the choice to reach iPhone and iPad users through web applications,
which were supposed to simplify development, introduces its own set of complications.
Maybe it’s time to make the leap and start developing native iOS apps. This chapter
highlights iOS features you can use if you choose to develop native apps—features that
are not available to web-only apps. Even if your app designs don’t require a lot of native
OS support, a native app still has advantages over web apps. To provide a fair and
balanced picture, I’ll also discuss what you lose by using a native app over a web app.
1
Using an App Offline
It is hard to argue with the fact that iOS devices are intended to be used in a connected
world. WiFi is built into all devices by default; iPhones and iPads (and likely future
devices) equipped with 3G also have cellular data connections that free users from
lurking around WiFi hotspots. Unfortunately, users may be out of WiFi range, have
no cellular connection, be running dangerously low on battery power, or be secured
inside a jet-powered flying metal tube whose attendants prohibit radio contact with the
ground. When an iOS device cannot access the Internet, a traditional web app—which
resides entirely on your web server—is not accessible. Although it is possible to code
a browser-based web app to be copied and stored on a device, the mechanism isn’t
foolproof.
A native app, however, is at least launchable even when the device has no connection
to the Internet. Exactly how usable the app is while offline depends on the nature of
the app, of course, but it’s clear from the apps that Apple supplies on every device that
an iOS device does not completely die if Internet connectivity is missing. You can still
listen to music, watch previously downloaded videos, look up your contacts, and tap
out notes; with an iPhone and iPod touch, you can still be awoken by an alarm or
calculate a total; and with any camera-equipped device, you can take pictures. Appli-
cations you download from the App Store let you do tons more things, such as play
games, read gorgeous-looking downloaded books, edit photos, figure out restaurant
bill tips, look up a dictionary definition, or identify a bird in the nearest tree—all with-
out the need for a constant Internet connection.
Many native apps also connect with the Internet for some functions. Games commonly
upload scores so you can see how well you perform against other users around the
world. Many apps also rely on the Internet for up-to-date information, such as email
apps, news readers, weather apps, Twitter and Facebook clients, and many more. For
designers of many of these types of apps, the challenge is to create an app that can
perform its basic functions offline, even if it means the user needs to download some
current content before cutting the wireless cord. Once disconnected from the cloud
(perhaps even while flying above the clouds), the user can relaunch the app and still
access fairly recent content.
Unfortunately, you cannot rely on Mobile Safari to preserve a downloaded web page’s
content for long. Even if the user manages to keep the Safari window open, restoring
it for use sometimes causes the page to attempt to reload itself from the server. No
server? No content, even though it may be in a cache someplace on the device.
Some web apps have successfully been converted to bookmarklets. A bookmarklet is a
browser bookmark that contains a javascript: or data: URL whose code generates the
HTML, CSS, image data, and JavaScript code for a web page when chosen from the
browser’s bookmarks list. It’s true that this method allows a web app to be stored
entirely on the user’s device, but a web page generated in this fashion has some
2 | Chapter 1: Why Go Native?
additional limitations over regular web pages. For example, a bookmarklet app cannot
use browser cookies because of security restrictions in the browser.
Mobile Safari does support the HTML5 offline application cache. This mechanism
allows web app publishers to code their pages (and configure their web servers) in a
way that allows the browser to store a copy of a web page and additional resources
(e.g., images) on the device. Developers deploying this technique have a variety of limits
to attend to, such as a maximum of 25 KB for any resource file, including any images.
Of greater concern, however, is that if the user reboots the device (completely powering
down the unit), all data in this offline cache can be lost. Native apps, however, survive
such system reboots every time.
There is a risk that when you have been designing Internet-based content and software
for a long time, you tend to take Internet connectivity for granted—after all, you have
always-on broadband at home or work. Additionally, all the buzz about cloud com-
puting makes it sound as though every computer user on the planet has ubiquitous and
nearly free access to an Internet that is as reliable as the sun rising tomorrow morning.
That is not always the case for all users.
More Access to the Hardware
Itdoesn’ttakelongtolearnthatwebpagesdevelopedforgeneral-purposewebbrowsers
are encumbered with many restrictions. For example, a web page does not have free
rein over the host computer’s filesystem, making it impossible for well-meaning scripts
to read or write files on the hard disk (except for closely monitored dedicated files for
items such as cookies and HTML5 data storage). JavaScript is granted very limited
access to even the host browser’s environment or settings. Despite the possible con-
venience afforded by automatically adding the current web page to a user’s bookmarks
list, such access is out of bounds for web pages.
All of these restrictions, of course, are imposed for the sake of security and privacy. Left
unfettered, a script on a malicious hacker’s website could wreak havoc on every browser
that lands at the site. Not many users would like unknown computers reading their
recent browser histories or replacing system files with ones that could cause banking
website visits to be redirected to lookalike phony sites that capture usernames and
passwords. Cyber crooks are constantly on the prowl for vulnerabilities in popular
browsers that they can exploit without the user’s knowledge—the so-called drive-by
attacks that have plagued various browsers through the years.
An application designed to run natively on popular desktop computer operating sys-
tems, on the other hand, typically has exceptionally broad freedom to rummage around
the computer at will. On some operating systems that are set up for user accounts, the
user must grant specific permission to the program’s installer. Such permission is taken
to mean that the user trusts the installer and the program(s) it installs to do no harm.
Developers who publish software with a goal of building a software business avoid
More Access to the Hardware | 3
doing bad things to customers’ computers even though users essentially hand over the
key to the system. On the other hand, if a program has a hidden agenda (e.g., loading
spyware onto every user’s computer), the nefarious activity will likely be discovered
sooner or later. News of the offenses will carry quickly across the Internet and the
company’s reputation will be ruined.
Apple engineers have thus far greatly restricted the hardware features available to web
apps running in Mobile Safari. Despite some cool hardware, such as the digital compass
in the iPhone 3GS, web apps simply have no access to most of the neat stuff. About the
only hardware-based features that a web app can count on are:
• Accelerometer orientation changes (e.g., portrait or landscape)
• Gyroscope motion (iOS 4.2 or later)
• Multitouch events (e.g., two-finger pinching or stretching)
• Location services (as many as are supported by the device)
Native apps, however, have substantially more access to the hardware—although not
necessarily every piece that developers might like. For example, apps built for devices
containing cameras can capture images (and video, where available) to facilitate image
editing tasks. Devices equipped with a digital compass expose the current heading of
the device. Sound captured by the device’s built-in (or plugged-in) microphone can be
recorded and further processed by code inside a native app. An app can read informa-
tion about the battery state and an iPhone’s proximity detector (which knows when a
user has the handset near her face). Native apps can also read from and write to files
of their own construction (albeit within some security-driven confines of the directory
structure reserved for the app).
Although Apple has begun to expose limited parts of the hardware to web apps
(essentially creating objects, properties, and methods that extend the DOM), such
exposure lags well behind the range of hardware features waiting to be used by native
app developers. I expect more hardware access to come in future iOS versions, but
web app access will likely stay several steps behind native app capabilities.
More Access to the Software
On the software side of the iOS, native app development offers a wide range of features
that web app developers don’t typically have available. For example, here is a list of
software features introduced with iPhone OS 3.0 that are available only to native apps:
• iPod library access to read library contents and play tracks
• Displaying interactive embedded Google Maps with many of the same capabilities
and identical performance to that of the Maps app
• Peer-to-peer communications for multiplayer game play
• Precise control over how cut/copy/paste works in an app
4 | Chapter 1: Why Go Native?
• Powerful structured data mechanisms ideally suited to displaying lists (the Core
Data framework)
• Precise control over audio recording details (sampling rates, audio formats, etc.)
• Push notifications to signal users about important events that launch your app
• Creating and sending email messages from within the app
• Reading and selecting information from the Contacts app
• Very powerful OpenGL ES 2.0 3-D graphics composition platform
• In-app purchases to encourage users to add paid features or extend subscriptions
If that list doesn’t send your imagination into overdrive, perhaps several new native
app features of iOS 4 will:
• Playing audible media while the app is suspended in the multitasking environment
• Receiving system notifications of changing between active and suspended mode
• Posting notifications to users at predetermined times, even if the app is suspended
• Integrating with Calendar app data
• Displaying revenue-generating advertisements from Apple’s iAd service
It’s not uncommon for native app developers to apply several of these advanced
software features (along with hardware features mentioned in the previous section) to
augment their apps. For example, one of my own native apps, iFeltThat Earthquake,
uses the in-app email feature to make it easy for users to contact me with questions
and suggestions about the app. The app also lets users select an entry from their
Contacts list to create a geographical center point around which recent earthquake
activity is shown (the app uses geocoding to convert a contact’s street address to map
coordinates).
All of this native software goodness still allows developers to fold useful web content
into a native application. iOS supplies a mechanism for displaying live web content
within a native app. The “viewer” used for such web content has all the HTML, CSS,
and JavaScript features of Mobile Safari (and its WebKit engine), but without the
chrome of the Safari app. You simply define a rectangular viewing region on the screen
and supply a URL to the web viewer. In iFeltThat Earthquake, for example, I keep users
informed about news and user tips via an HTML-authored page made available from
a web server. Each time the app launches, it looks to see if the news web page has been
modified since the last visit; if so, it downloads the page, stores a copy on the device,
and signals the user that a news flash is available for reading.
I chose to compose the news material in HTML for a couple of reasons. First, as a
veteran HTML handcoder, I am, of course, comfortable generating content in that
format. It allows for quick composition and easy testing of the page from a local server
using Mobile Safari on an iPhone-compatible device. It also means I am free to change
the styles (CSS) of the news page without having to update the entire app. The second
reason for choosing HTML is that I can easily provide links to other HTML content,
More Access to the Software | 5
whether composed by me or served from a different external source. Because the news
page is shown within a web viewer inside the app, links operate as they do in any
browser, replacing the current page with the destination of the link. My in-app web
viewer provides just a minimum of browser controls for reloading, stopping a load, and
back and forward navigation.
In many ways, web development skills are powerful adjuncts to native iOS app devel-
opment. Being comfortable in both environments means you can call on the right
deployment tool for various parts of a native app. Hardcore Objective-C and Cocoa
developers might be wary or unaware of the web powers that you have in your hip
pocket. Once you master native app development, you’ll have a distinct advantage over
your Objective-C-only colleagues.
What You Lose
By and large, the full iOS SDK feature set offers your app designs far more flexibility
and the ability to recreate the full range of user interface features you see on Apple’s
own apps and apps developed by third parties. But there are costs—in monetary and
toil currencies—to obtain those native app powers.
Except for apps designed for in-house corporate use, native apps that run on
nonmodified devices—i.e., iPhones and iPads that have not been jailbroken (hacked
to allow unapproved third-party apps)—must be distributed via the iTunes App
Store. This is both a blessing and, for some, a curse for several reasons.
About Jailbreaking
When the first-generation iPhone landed in developers’ hands in 2007, quite a few
programmers were put off by the lack of a publicly available development environment
for applications. Apple granted itself the power to build native apps included with the
phone, but the developer community was shunted to the web app world—with a
Mobile Safari version boasting far fewer app-friendly features than today’s HTML5-
empowered model. Some adventurous programmers, however, found ways to gain
access to the same interior programming functionality that Apple’s engineers had and
opened up native programming to third parties. Having pierced through Apple’s re-
strictions, they called the technique jailbreaking. To run one of these independent apps,
an iPhone user had to “jailbreak” the device using a software-run process that grew
easier and easier over time as jailbreaking tools improved.
Several months after the initial iPhone debut—and perhaps pushed by the encroaching
jailbreak programming efforts—Apple released the iPhone SDK to allow third parties
to write native apps, but only with publicly documented routines. That restriction still
rankles some developers, so jailbreaking is still alive today, even as Apple continually
opens more internal routines to all developers. Jailbroken devices reportedly account
for as much as 10% of the world’s iPhone and iPad population (but a higher percentage
ofactivetechbloggers,whomakejailbreakingseemmoreprevalentthanitis).Although
6 | Chapter 1: Why Go Native?
jailbroken devices can still download apps from Apple’s App Store, a separate store,
called Cydia Store, offers apps designed for jailbroken iPhones and iPads.
Some programmers believe it is almost an obligation to jailbreak their devices, lest they
appear captive to the will of Steve Jobs. I personally prefer not to jailbreak my devices,
for practical, rather than ideological, reasons: I want to know that when I test my App
Store apps, the devices are working like the ones owned by 90% or more of my potential
customer base. The ultimate choice, however, is yours.
Distribution
On the one hand, since the App Store is a single point of distribution, all users of
unhacked iPhone, iPod touch, and iPad devices go to the App Store in search of apps
that will help them scratch an itch. While you may have to choose your app’s descrip-
tion keywords carefully to help potential users search for your product, at least you
don’t have to play search engine optimization games to get your app high in search
engine results.
On the other hand, the App Store becomes the one-and-only gatekeeper between your
app and the consuming public. You must submit your finished app to the App Store
for approval before it appears in the store. Approval times can vary widely, often with-
out explanation. Sometimes it’s a matter of only a couple of days; other times it can
take weeks. The same is true for updates to existing apps. If you need to issue an update
to fix a bug, the approval time can be just as long—and, inexplicably, sometimes
longer—to get that maintenance release out to the world. You can apply for an emer-
gency update to help hasten the approval, but if you abuse that privilege, you risk
upsetting the gatekeepers.
App Updates
Speaking of updates, the web app scenario is far superior to the App Store native app.
You instantly deploy an update to the server that hosts the web app whenever you want,
as often as you want. This encourages web app developers to issue frequent incremental
updates rather than storing up fixes to submit to the App Store in less-frequent batches.
If your app updates are more content-oriented, you can still pass along those updates
to a native app in a couple of ways. I described earlier how I use HTML to supply my
native apps with news updates. Similarly, updated material can be supplied in other
formats(e.g.,propertylistXMLfiles),whichanativeappcanreadwheneveritlaunches.
Users can save newly acquired material to the device so that it is available to the app
even if the device is not connected to the Internet the next time the app launches.
Implementing this approach to updating an app takes a bit of advance planning, so it
is well worth exploring the possibility early in the design phases of any iOS app.
What You Lose | 7
Apple iOS Developer Program
A prerequisite to submitting a native app to the App Store is an annual paid membership
to the iOS (formerly iPhone) Developer Program. The current fee is $99.00 per year.
Membership lets you obtain the necessary digital certificates that permit developers to
load native apps onto test devices and to upload finished apps to the App Store for
approval. You also have access to beta versions of the next version of iOS SDK and iOS
software (all under nondisclosure agreements, so you can’t blab about them).
In addition to paying the developer program fee, you must also complete a distribution
contract with Apple. For paid applications, the contract process also requires that you
establish banking relations with Apple. As with app approvals, the time required to
complete the contract varies depending how busy Apple is. It’s not something to leave
to the last minute, because it can take several weeks to complete, even longer for
developers outside of the United States. Once you pay for the iOS Developer Program,
you should begin the contract process, even as you work on your first native app.
Content
As the gatekeeper to “shelf space” on the App Store, Apple’s approval process also
imposes restrictions on the content of native apps. Your developer agreements spell
out the fundamental guidelines, but Apple inspects each app for compliance on a case-
by-case basis.
Such is not the case for web apps. You can serve up whatever you want (within the
confines of your own local laws, of course) because the web app is hosted on your server
and the device’s owner can freely decide to visit your server or skip it.
If you are already aware that web apps—indeed any content designed to be played
through the Mobile Safari browser—cannot avail themselves of Flash or Java, you
should also be aware that native apps don’t get you any further with respect to those
two software platforms. As of this writing, iOS does not natively support either runtime
environment.
Authoring Platform Choices
You can write HTML, CSS, and JavaScript code with a text editor on any operating
system platform of virtually any generation. Plain text editing doesn’t even require a
graphical user interface, which is why you can find plenty of Unix programmers com-
posing web code in command-line interface editors, such as Emacs and vi (or variants
thereof). The key to this flexibility is that conversion to machine code occurs in the web
browser. Such is not the case for writing native apps.
8 | Chapter 1: Why Go Native?
Developing native iOS apps requires Apple’s integrated development environment
(IDE) called Xcode (pronounced EKS-code). Even though Windows users can sync
their iOS devices to their PCs via iTunes for Windows, the Xcode IDE is available only
for Macintosh computers.
Taking the Plunge
Beginning with the next chapter, you will see the changes to the development process
and programming environment that you will have to adopt to develop native apps.
Some of the changes are radical, so if you jump into the programming environment
cold, the transition will seem overwhelming. But, just as you learned the intricacies of
CSS, JavaScript, and the DOM, the same will happen with iOS SDK development with
practice and experience: throughout this book, you’ll learn new concepts that build
upon one another. My purpose here is to help you embrace that transition by putting
new items in the context of your existing knowledge.
Let’s get started.
Taking the Plunge | 9
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman
CHAPTER 2
Welcome to the iOS SDK
Even in these days of powerful high-level web authoring tools, it’s still quite common
for JavaScript programmers to compose or modify code with nothing more sophisti-
cated than a text editor. Perhaps you use that text editor to work on .html, .css,
and .js files that users access directly; or you use that text editor to write server code
(in Python, Perl, Ruby on Rails, or one of several other languages), which in turn
assembles HTML code served up to requesting browsers. With the browser operating
as a code interpreter (even if it performs some fast precompiling behind the scenes),
the write-test-debug cycle is pretty fast: make a code change and reload the browser to
test the results. Egregious errors, such as JavaScript syntax errors, signal themselves
while the page loads; more subtle errors, such as referencing an object that hasn’t yet
been created, fill the error console when the code runs.
When you switch to native app development, this comfy authoring environment and
cycle go out the window. Luckily, it’s replaced with an integrated and visually oriented
environment that—once you learn its ways—reflects a lot of the best in modern pro-
gramming environments. This is the native iOS app SDK, whose nucleus is Xcode.
Among other things, Xcode helps you visualize and manage the potentially large num-
ber of files associated with each app in development.
Additionally, the tools delivered with Xcode are highly integrated. For example, you
will write some code that responds to a user tapping a button in an iPhone app: the
tool you use to create the user interface is aware of the code you’ve written and helps
you connect the button in the user interface to that code. The user interface building
tool is instantly aware of changes you make to the code, even though the tools are two
separate programs in the Dock.
Hardware and OS Requirements
As mentioned in Chapter 1, you need an Intel-based Macintosh running Mac OS
X version 10.6 (Snow Leopard) or later to use the Xcode IDE. As Apple releases new
versions of the iOS SDK and Mac OS X, requirements may change.
11
You don’t need a brand-spanking-new Intel-based Mac to develop iOS apps. There are
plenty of used Intel Macs for sale on eBay and elsewhere. For the tower- or iMac-averse,
laptop styles—MacBooks and MacBook Pros—are well suited for iOS development,
except perhaps for a possibly small screen. If you can afford a large external LCD mon-
itor, you will have an easier time managing your project windows. And maxing out a
laptop’s RAM slots will also contribute to good performance of Xcode.
Installing the SDK
To begin your exploration of iPhone development, start by signing up to become a
Registered iOS Developer at:
http://developer.apple.com/programs/start/standard/
Registration requires that you have an Apple ID. If you have an iTunes account or if
you have purchased from the Apple Online Store, you already have an Apple ID.
Otherwise, you can sign up for one online while you register as an iOS Developer.
The free version of the iOS Developer program lets you download the full SDK from
the opening page of the iOS section of the Apple Developer website. Be sure to confirm
you have the minimum Mac OS X version required for the current SDK you’re about
to download.
The iOS SDK is huge—well over three gigabytes. Be patient with the download. It
arrives as a compressed disk image, a file with a .dmg extension that expands into a
mounted disk volume. If the completely downloaded file does not automatically ex-
pand, double-click the file to mount the disk image on your Desktop (some browsers
will do this for you automatically after the download is complete). The disk image will
open itself to reveal installer notes and a package file containing the SDK (Figure 2-1).
Double-click the .mpkg package file to run the SDK installer. I recommend following
the default choices presented at each step of the installation process. Allow the SDK to
be installed in a new Developer directory on your startup disk. If you have iTunes
running, you will be prompted to quit the app before the installation will complete.
After installation has finished, you can drag the disk image and compressed image file
to the Trash.
About iOS Developer Programs
The free version of the iOS Developer program allows you to use the SDK to run native
apps you create only on the iOS Simulator program (one of the SDK tools), which runs
only on the Mac. To upload a native app to an actual device for testing (or your own
use) and to submit an app for distribution through the App Store, you must sign up for
the $99.00 (per year) iOS Developer Program (or the $299.00 Enterprise Program for
companies planning to write apps only for employee use). This paid developer program
also grants you access to an Apple-hosted online forum where you can ask for coding
12 | Chapter 2: Welcome to the iOS SDK
help (or read how others may have already solved your problem). Additionally, when
Apple releases beta versions of the next iOS version and associated SDK, paid members
can download those pieces for development and testing purposes. For example, on the
day that iPhone OS 4.0 was announced in April 2010, members of the developer pro-
gram could download a beta version of Xcode to write apps and a beta version of the
OS to install on devices to see how the new features worked.
You will not be able to submit apps to the Store that you have built from
a beta version of the SDK. Therefore, if you have one or more apps on
the App Store, you should always keep a current version of the SDK
on hand for building updates to existing apps. Historically, it has been
possible to install both the current and beta SDK versions on a single
Mac,ifdesired(youstillneedtoinstallthebetaSDKinaseparatefolder).
You can go pretty far toward developing your first iOS app without investing a dime
in Apple developer programs. It’s a free way to discover if programming for iOS in the
Objective-C language is right for you. But don’t wait too long to decide to sign up for
the paid program. Once you sign up for that program, but before any app you create
can appear on the App Store, you must still go through a contract and banking cre-
dentials process with Apple, all of which is handled online. Each developer has had a
different experience with completing the contract and banking agreements. For some,
the process takes only a few days; for others, it can take months. What you want to
avoid is waiting to begin the contract process until you submit your first app to the App
Store. In my case, the first app I submitted in early 2009 was approved in three days;
the contract, however, took almost one month, during which time my approved app
sat in limbo.
Figure 2-1. Contents of the iOS SDK disk image
About iOS Developer Programs | 13
Inside the SDK
TheDeveloperdirectorycontainingtheiOSSDKiswellovereightgigabytesofgoodness
waiting for you to explore. You will spend most of your time in four applications, three
of which are highlighted in Figure 2-2.
Figure 2-2. Three primary applications of the iOS SDK (version 3.2.5 shown)
The four primary tools are:
Xcode
This is the integrated development environment where you will write your code,
keep track of external files (images and others), and build your app for testing and
eventual submission to the App Store.
14 | Chapter 2: Welcome to the iOS SDK
Interface Builder
You are not required to design your user interfaces using this graphically oriented
design tool, but if your app utilizes standard iPhone or iPad user interface elements,
it can significantly reduce the amount of code you write.
Instruments
After your app reaches a usable form, you will use Instruments to observe how well
it uses memory and system resources.
iOS Simulator
Although the iOS Simulator app is buried elsewhere within the Developer
directory hierarchy, you will use it often during all development phases for both
iPhone and iPad testing (the tool contains simulators for both platforms). The
simulator launches from your Xcode project windows.
Each time you go to work on your app, you begin by launching Xcode. You can launch
all of the other supporting apps directly from within Xcode. For example, when you
want to see how well the current implementation runs on the iOS Simulator, you will
instruct Xcode to build the app and run it on the simulator. If the simulator is not yet
running, Xcode will launch it, install the app, and launch the app on the simulator.
Viewing Developer Documentation
The first time you launch Xcode, you will see a Welcome to Xcode window with a
variety of choices, as well as a list of previously opened projects (probably empty for
you). Click Cancel for now. Instead, open the Help menu and choose Developer Doc-
umentation, as shown in Figure 2-3. You will be referring to documentation a lot, and
this menu (or keyboard equivalent) is a quick way to open the documentation window
before you open a project.
Figure 2-3. Accessing developer documentation in Xcode
Viewing Developer Documentation | 15
The best place to begin in the developer docs is the home page for the latest iOS SDK
you are using. Figure 2-4 shows where the main navigation menu is located and what
the home page looks like. The Xcode documentation system can display multiple sets
of documentation for different iOS versions and Mac OS X development (selectable in
Xcode preferences). Figure 2-4 shows only the iOS 4.2 doc set installed.
Figure 2-4. iOS 4.2 SDK documentation home page
After you’ve finished this book, the Getting Started section (upper right box in Fig-
ure 2-4) is the place to go next. You’ll have enough links to keep you busy for quite a
while.
While we’re on the subject of the developer docs, let me also show you how you will
interact with the iOS Reference Library while you compose your code. In particular,
you will frequently need to look up how various objects work. Simply enter a term into
the Search box in the upper-right corner. For example, by the time you are finished
with this book, you will know that Objective-C arrays are instances of the NSArray
object. To read the details of the NSArray object, simply enter the object name into the
case-insensitive Search box (Figure 2-5).
The left column contains a list of documents and items within those documents that
match the search string. If you have multiple documentation sets for different iOS
16 | Chapter 2: Welcome to the iOS SDK
versions installed in your copy of Xcode, the search results will show separate entries
for each version—all named the same. This can be confusing at first glance, but you
can hold the pointer over any item in the returned list to see the doc set to which that
item belongs, as shown in Figure 2-6, which shows what the top of the search results
looks like when two iOS doc sets are installed.
Figure 2-6. Hover over an item to reveal its doc set
As shown in the middle and right columns of results of the NSArray search (Fig-
ure 2-5), reference documents frequently include links to various programming guides
and sample code projects that come with the SDK. Each programming guide is a gold-
mine of information, especially for programmers who are new to the guide’s subject
matter. Read those guides thoroughly—and perhaps multiple times—to learn the gos-
pel according to Apple. Very often, these documents assume you have a working
Figure 2-5. Searching for details on the NSArray object
Viewing Developer Documentation | 17
knowledge of Objective-C and other aspects of the iOS SDK, most of which you will
be exposed to throughout this book.
Loading Code Samples
A comparatively recent innovation in the iOS SDK is a simplified way to open a copy
of a code sample that you can play with at will without worrying about messing up the
original. Figure 2-7 shows the result of clicking on a link to a code sample—called
TheElements—shown at the bottom of the right pane in Figure 2-5. For sample code,
the Table of Contents panel lists the files associated with the sample project. Direct
your attention to the button on the righthand panel.
Figure 2-7. Landing page for the TheElements code sample
Use the following steps to load the sample into Xcode:
1. Click the Open Project in Xcode button.
2. Select the folder where the installer will create the project’s folder (i.e., a folder
named TheElements will be created for you, so choose where you want that
folder to go).
18 | Chapter 2: Welcome to the iOS SDK
3. Click Choose.
The installer script copies all necessary files into a folder named TheElements and
immediately launches the project file, named TheElements.xcodeproj. A .xcodeproj file
is the master hub for everything associated with the app and is the file you open when-
ever you want to work on an app. Figure 2-8 shows the Xcode project window for
TheElements sample project.
Figure 2-8. TheElements project window in Xcode
While the project window may look intimidating at first, you won’t be dealing with
most of what you see here on a daily basis. Your focus will primarily be on items listed
in the lefthand Groups & Files section and mostly on items in the top group (above the
Targets group). This is where your source code files, images, and other contributing
files for the app go.
The column view of the project contents shown in the top right-hand pane is another
view you won’t be looking at much, if at all. Instead, drag the divider between the two
right-hand panes upward all the way to give yourself a larger source code editor view
(see Figure 2-9). Because no file is selected yet, the editor pane reads “No Editor.”
You can now open the various group folders to expose individual source code files.
When you click any source file, the appropriate editor appears in the editor pane, as
shown in Figure 2-10.
Loading Code Samples | 19
Figure 2-10. Select a source code file to view its contents in the editor
Figure 2-9. Drag the bottom divider upward to reveal more of the editor
20 | Chapter 2: Welcome to the iOS SDK
Sample source code files supplied by Apple almost always begin with a lengthy com-
ment (in green text according to the default text-color scheme). After a brief description
of the file comes a lot of legal and licensing text. The actual code comes afterward. Feel
free to scroll down the editor to get a taste of what iOS SDK app source code in
Objective-C looks like.
Coding Styles in SDK Samples
Different Apple engineers write code samples supplied with the SDK. You will therefore
find a variety of styles in the way projects are composed. The lack of uniformity can be
confusing to newcomers who desperately want to adopt a solid coding style. At best,
you should look to the samples as just that: mixed samples rather than specific
instructions on how to structure projects, name variables and methods, or even how
to divide code into separate files. Additionally, most samples aim to demonstrate a
specific concept rather than define an all-around best practice example. Pieces of some
samples distant from the primary subject matter may even be less than optimal. There-
fore, as you learn more about Objective-C and the SDK, don’t be afraid to employ your
own structure and styles that are comfortable for you.
Setting the Project’s Base SDK
You probably noticed that the Overview menu at the upper-left corner of the project
window says “Base SDK Missing.” Before you can compile an app and run it, you need
to set the SDK version Xcode should use for compilation and deployment. Because
TheElements project was created when SDK version 3.0 was still available and
modified to build for iOS 4.0, Xcode in the iOS 4.2 SDK doesn’t recognize the setting
as being valid. It’s time to bring the setting up to date by adjusting what is known as
the Target—a collection of specs Xcode uses to build an application around the source
code of the project.
Open the target’s settings by choosing Project→Edit Active Target “TheElements”. You
will see the Target Info window. In the first group of settings is the Base SDK, which
confirms that the originally specified SDK 4.0 is not available. Click in the right column
to reveal your possible Base SDK choices, as shown in Figure 2-11. Choose Latest iOS.
This setting will allow the project to work in future SDK versions without further
adjustment.
Close the Target Info window. The Overview menu should now indicate “4.2|Debug|
TheElements” or similar indications. If the Overview menu doesn’t change, close and
reopen the project. In the next chapter, you will work with an additional setting that
will let your app work with iPhone devices running OS versions as early as 3.0—even
though the Base SDK is still set to 4.2.
Setting the Project’s Base SDK | 21
Trying the iOS Simulator
To make sure your Xcode installation and sample code are working properly, you
should try running the sample in the iOS Simulator. The first step is to direct Xcode to
build the app for the simulator rather than for a device. You don’t have the necessary
certificate to load this app onto an actual device, so the simulator will do for now.
Near the upper-left corner, click the Overview drop-down menu. Choose Simulator,
as shown in Figure 2-12, if it is not already chosen. Then, choose TheElements - iPhone
Simulator 4.2 from the Active Executable group.
Next, click the Build and Run button in the center of the top toolbar
You will see the stages of the build process displayed in the lower-left corner of the
Xcode project window. After a few moments, the iOS Simulator will launch (it’s a
separate application from Xcode), and the TheElements app will automatically launch,
as shown in Figure 2-13.
Figure 2-11. Setting the project to use the latest iOS version as the Base SDK
22 | Chapter 2: Welcome to the iOS SDK
Figure 2-13. TheElements app running in iOS Simulator
Figure 2-12. Instruct Xcode to build for the simulator running iOS 4.2
Trying the iOS Simulator | 23
Use the mouse as your finger to scroll through the list and click on buttons. Although
there aren’t any images to zoom in this app, if you want to use a two-finger pinch or
stretch gesture, hold down the Option key while clicking and dragging inside the sim-
ulator’s active app area (you’ll see grey dots representing finger touch spots). When
you quit the app on the simulator (by clicking the Home button at the bottom center),
you will see an icon for the app on the iPhone home screen. The icon is one of the image
files that came with the collection of files for the project.
Coming Up...
At this stage of your exposure to Xcode, don’t bother trying to figure out the files and
structure of the sample TheElements app—it has a lot of moving parts that probably
won’t make much sense yet. By the time you reach Chapter 8, however, you’ll be ready
for a more detailed walk-through of this project’s component files. In the meantime,
there is plenty of language material to cover. But before we get to the new language
stuff, we have one more stop to make: using Xcode to create a test workbench app in
which you’ll be able to study how the Objective-C language and iOS features covered
in later chapters work.
24 | Chapter 2: Welcome to the iOS SDK
CHAPTER 3
Creating a Test Workbench
If there is one comfortable technique to which we HTML, CSS, and JavaScript devel-
opers have grown accustomed, it is writing some tiny code samples to test expression
evaluations and execution logic. You very likely have at least one test.html file some-
where on your hard drive. In one of my JavaScript books, I include code for a page
called The Evaluator, which allows readers (and, more importantly, me) to see values
ofsingle-lineexpressionsandobtainpropertydumpsofobjects(listsofpropertynames,
values, and value types for any JavaScript or DOM object in the page).
It’s convenient to test code snippets initially in an environment that is isolated from
your major work in progress. First, you don’t want other code to influence your ex-
periment(think“scientificmethod”).Second,youdon’twantyourexperimentstomess
up your existing working code. The Workbench app you will build in this chapter will
provide you with a running iPhone environment (initially on the iPhone Simulator) in
which you can easily test expressions, logic, and the like. Use it as a learning lab while
you work through the remaining chapters of this book.
Figure 3-1 shows the finished app. True, it’s nothing more than an iPhone screen with
a button on it. You will set up this app so that you can test your code in the iPhone
OS runtime environment by clicking that button. Results will appear in a separate
window of Xcode, called the Console (more about that later). The purpose of the
Workbench app is to provide a clean environment into which you can insert your little
Objective-C experiments and other learning explorations, which all get triggered when
you click that button.
In the process of building Workbench, you will be simply following my instructions.
I don’t expect you to understand everything that is going on, but I will explain many
concepts to you as we go. For example, you’ll begin to appreciate the importance
of choosing good names for projects in “Naming and Saving the New
Project” on page 29. Later you will get to play with Interface Builder to design the
layout. If you don’t fully grasp why something is the way it is, don’t worry—future
chapters will cover most of these concepts in more depth, while your future introduc-
tions to iOS SDK programming will cover the rest.
25
Creating the Project in Xcode
Every iOS app you generate with Xcode is managed within a container known as a
project. The project file (with a file extension of .xcodeproj) knows all of your preference
settings for the particular app, maintains lists of source code and other external files
associated with the project, and tracks many more pieces that most app developers
don’t ever touch. Each time you come back to an app you’ve already begun, you will
open its project file to get back to work.
For the Workbench app, begin by creating a new project. Do so from the File menu in
Xcode, as shown in Figure 3-2.
Selecting a Project Type
The New Project menu item presents a dialog box of choices (Figure 3-3). Because
Xcode is used for both iOS and Mac OS X development, you will see options for both
environments (even though you downloaded Xcode with the iOS SDK from the Apple
developer site, it includes the development tools for Mac OS X as well). You obviously
want to focus on the iOS section, and pay attention to the options for creating apps
within that section.
Figure 3-1. The Workbench app
26 | Chapter 3: Creating a Test Workbench
The type of application you choose at this juncture determines the content of the pre-
written files Xcode generates for a brand new project. Apple’s Developer Tools group
has gone to great pains to supply as much template code as possible to help you start
your way into an app. In fact, each project template is finished enough to the point that
you can create an “empty” project, build it, and install it on the simulator. It won’t do
anything, but the fundamentals of an actual running iPhone or iPad app are supplied
for you in the new project template.
Knowing how to select the right template type comes with more experience than
you have at this point, so take my word for it that a view-based application is the
one you want for Workbench. Although other types would also work, it will
ultimately be helpful for your experiments to have the view-based infrastructure in
place.
Select the View-based Application icon in the New Project window, and click Choose.
Device-Specific or Universal App?
When you select View-based Application in the New Project window, the Product
menu allows you to produce the fundamental code for either an iPhone- or iPad-
specific app. An iPhone-specific app will run on an iPad in a small display area (which
the user can upscale to a full-screen view that is usually not very pretty), but an iPad-
specific app cannot run on an iPhone. Xcode provides a starting point for a single
Figure 3-2. Create a new project menu choice
Creating the Project in Xcode | 27
“universal” app that contains code for iPhone- and iPad-specific areas in one final app
file that you can upload to the App Store. You can see that choice in the New Project
window by clicking on Window-based Application and viewing the Product menu.
Universal apps tend to have identical functionality for both versions, with its device-
specific code providing tweaks that reflect the differences between the platforms in user
interface design and screen sizes. An advantage to this approach is that you can use a
single set of underlying code to handle data, network communications, and so on for
both device families. The App Store, however, also has many examples of completely
separate versions of an app, in which the iPad version offers additional features suited
to the larger screen. Although it might require more work on your part to keep code
shared between the two versions of the app in sync with each other as you release
upgrades, it’s not uncommon to find enhanced iPad versions of an app commanding
a higher price on the App Store.
The choice between a Universal app and separate versions for iPhone and iPad is one
of those factors that you should keep in the back of your mind as you begin planning
your real apps. In the meantime, the fundamentals you’ll be learning in your early days
will apply equally to whichever product platform(s) you eventually choose.
Figure 3-3. Project choices
28 | Chapter 3: Creating a Test Workbench
Naming and Saving the New Project
Next you will be presented with a Save file dialog box. This is where you will specify
the location for the project folder and the name of the app. These are two separate
points that should be given a bit of thought.
Be aware that Xcode will create a folder for the project (using the name you will assign
in a moment). In other words, the folder location you choose in the New Project file
dialog box should be a kind of master folder into which you will place each of your iOS
SDK project folders (one project folder per app). By default, Xcode suggests placing
your apps in the user Documents directory. I prefer to keep all my projects for a par-
ticular minimum iOS version grouped together on my hard disk. Use an organization
scheme that makes the most sense for you.
Avoid the temptation to save your projects inside the Developer
directory created during SDK installation. A future SDK update could
invasively modify that directory’s contents. Save your projects
elsewhere.
The name you assign to a new project will ripple through the project’s files in ways that
will surprise the newcomer (you’ll get to see some of the implications later in this
chapter). Although the name you assign at this stage does not have to stay with the
app all the way to the App Store or to the app icon’s label in the home screen, I rec-
ommend not trying to be too clever while thinking up a project’s name, especially if
you have not yet figured out what you want to call the app in the App Store.
By convention, project file names begin with an uppercase letter, although this is not
an absolute requirement. One reason for this project naming convention is that Xcode
generates some project files and objects beginning with the name you assign, and those
files’ names typically begin with an uppercase letter.
For multiple-word project names, I recommend using CamelCase formatting rather
than spaces between the words. If you use spaces, Xcode will turn those spaces into
underscore characters for the filenames it generates.
For the Workbench project, assign the name Workbench and click Save.
Welcome to Your Project
After a little bit of churning, Xcode creates the new view-based project represented in
the window shown in Figure 3-4.
Let’s take a quick tour of the window, starting with important items in the toolbar at
the top.
Creating the Project in Xcode | 29
If you have previously customized Xcode, the makeup, order, or labels
of buttons and other items in the toolbar may look different from Fig-
ure 3-4. If you clicked the clear “lozenge” in the upper-right corner, you
won’t see a toolbar at all. Click it again to make the toolbar reappear.
The Overview pop-up menu is where you select how Xcode should build and run the
app. When it shows “Device” on the left side, it means that deployment will go to any
iPhone-compatible device that is currently connected to your Mac via USB cable and
designated as a development device (you will also need to be a member of the paid iOS
DeveloperProgram).Duringmostofyourdevelopment,youwillbeintheDebugmode,
and instead of loading the app onto a device, you will direct the app to load into
Simulator.
Continuing our tour of the toolbar, the Action menu contains commands that you
may issue on items selected in the Groups & Files list below. Your interaction with
this menu will likely be minimal, because most menu items are duplicated in the Xcode
menu bar. Once you start writing code and wish to step through code while it runs,
you will activate the Breakpoints button, which controls whether the next button reads
Build and Run (ignoring breakpoints) or Build and Debug. Clicking the Build button
in either form causes Xcode to compile your project and load the app onto a device or
into iOS Simulator (depending on the Overview setting).
Figure 3-4. The default Workbench project window
30 | Chapter 3: Creating a Test Workbench
As you have probably experienced with JavaScript debuggers, you set a
breakpoint in your source code by clicking in the column to the left of
any statement. With breakpoints enabled in Xcode, program execution
pauses at the designated line location. You can then step through your
code while observing variable values and following logic paths in the
separate Debugger window, available via Xcode’s Run menu.
The lower-left pane, labeled Groups & Files, is where you organize the files of your
project. Notice that the folder organization here is completely independent of the
organization of actual files in your project’s Finder folder. The purpose of this pane is
to let you collect all of the project’s external files into an organization that helps you
locate the files for editing, especially as a project grows to potentially dozens of files.
You can add groups (folder icons) as you go and change the organization at will; you
may even nest groups to multiple levels if it helps you keep things straight. Most of
your activity will be in the topmost group, whose name is that of your project. There-
fore, at this stage, don’t be put off by the long list of other items, many of which you
won’t deal with directly or regularly.
By default, the upper-right pane lists the items contained by whichever group is selected
in the Groups & Files pane. If an item’s name is shown in red, it means the file is
expected but doesn’t exist yet (or has been deleted from the project’s Finder folder).
For example, because you have not yet built the Workbench app, the compiled .app
file (in reality, it’s a package) does not yet exist (although it is expected to exist even-
tually) and is listed in red. If you select only a single file in the Groups & File list, that
file is the only one shown in the upper-right pane. Don’t worry about the columns at
the right at this point.
Finally, at the bottom right pane is the editor window where you write and edit source
code. It is more important to have a big editor window, and the upper-right pane’s
contents aren’t that important during code creation. Therefore, drag the divider
between the two right-hand panes upward so that you have only a single editor window,
as shown in Figure 3-5.
Editing Your First Files
To display a source code file in the editor window, select the file from the Groups &
Files pane. For Workbench, expand the Classes group and select the WorkbenchView-
Controller.h file, the third one in the group, as shown in Figure 3-5 (you’ll learn about
classes and the meaning of the .h and .m files in a later chapter).
Xcode created all of the code you see here. The file begins with several lines of
comments—yes, two forward slashes is one way to signify comments, just as in Java-
Script. The comment lines include the name of the file and its owning project, as well
as some identifying information, which Xcode has obtained from the system. You are
free to edit comments as you wish, including adding more lines if you need them.
Creating the Project in Xcode | 31
You’ll begin editing this file by specifying the syntax for the method that will ultimately
be triggered when you tap the button in the Workbench app. I’ve named the method
runMyCode:. Objective-C method definitions begin with either a minus sign (−) or plus
sign (+). Each sign has a specific meaning (described in Chapter 4), but for this method,
use the minus sign. In the WorkbenchViewController.h file, insert the following code
after the right curly brace, but before the line containing @end:
- (IBAction)runMyCode:(id)sender;
As you type, you’ll notice that Xcode tries to complete words automatically that it
recognizes, such as IBAction. If you wish to accept the suggested autocompletion, press
the Tab key, and the text insertion pointer zips to the end of the word.
Just like JavaScript, Objective-C is case sensitive, so be careful with your
typing. But unlike JavaScript, the semicolon at the end of a statement is
absolutely required. Omitting a semicolon at the end of an Objective-C
statement is like omitting the period at the end of an English sentence.
As shown in Figure 3-6, when you make a change to a file’s contents, the icon for that
file in the Groups & Files listing turns dark gray, signifying the file is “dirty.” Typing
Command-S saves the file and restores the “clean” icon.
Next comes editing the WorkbenchViewController.m file, where you’ll add the code
that actually runs when the method is invoked. Click the WorkbenchViewController.m
file in the Groups & Files listing to display the file’s contents in the editor pane. Then
Figure 3-5. Editing the WorkbenchViewController.h file
32 | Chapter 3: Creating a Test Workbench
Other documents randomly have
different content
all very interesting studies—the most unusual people he had ever
known. But, as the evening wore on, dissipated by cards and
gramophone selections, scraps of dancing executed fantastically by
Mrs. Manton and the enamoured stranger, whose name he did not
learn, he grew gradually weary of the desultory entertainment, and
wished Lee would return. At length he came. After receiving warm
welcomes from everyone present, he led Mauney up to his room.
The hallway on the first floor was too dark to give any view of the
place except that Lee’s room was at the front end of the corridor on
the right side, and when illuminated was seen to be a large,
comfortably furnished chamber with two windows facing Franklin
Street, and a flat-topped desk placed between the windows. Upon
the desk were a long row of large technical volumes, an ink-well,
blotters and a ruler. There were two big, leather-upholstered, easy
chairs in the outer corner of the room, facing each other, and a small
smoker’s stand between them. Lee raised the windows to freshen
the stale air, then turned in a general survey of the familiar place.
“What do you think of the bunch?” he asked casually, as he lit a
cigarette.
“I like them fine,” said Mauney. “They’re quite clever, these
people.”
“Oh, yes. So they are,” Lee agreed, as he dropped wearily into one
of the chairs and waved Mauney to the other. “Are you smoking?”
Mauney raised his hand.
“You know, Mr. Lee,” he smiled, “I’m just a green-horn from the
country. I’ve had quite a lot of new experiences to-day already. I’m
not snobbish about tobacco, but I’d rather leave that for another day
or two, if you don’t mind.”
“Fine,” laughed Lee. “You’ll get along in the world all right!”
“Do you think so?”
“Surely. You don’t need to take my word for it. I find that Gertrude
is an extremely shrewd judge of men, and I’d like to tell you what
she said about you—if you wouldn’t misunderstand her.”
Mauney was greatly interested. “No, I won’t. I like her a lot. What
did she say?”
“Well, she said in the kitchen, while she was making those
sandwiches, ‘Where did you get this big, refreshing country breeze,
Max?’ I told her you were coming to the city for the first time to take
up some kind of academic work, and she looked up at me as if
surprised. ‘Clever kid,’ she said. ‘He walked right over to me like a
confidence man at the start. I pretty near gave him my heart.’ Now,
of course,” added Lee, “when Gertrude feels that way about
anybody, he’s elected!”
“How do you mean?”
“Why, the house is yours. You can stay and board here. In other
words, you gibe, fit in, dovetail—do you get me? I told her you
might like to remain here, and she just nodded, which means that
to-morrow night, without anything being said about it, a room will
be ready for you to occupy.”
“Do I pay in advance?” Mauney enquired.
“No, no,” laughed Lee, as if at his friend’s inexorable ignorance;
“you don’t do anything of the kind. She may not ask you for money
for a month. Then she’s liable to suggest it very delicately, and, as a
rule, you give her just a little more than it’s worth—see? You pay for
atmosphere here and for her peculiar selection of other guests.”
“How much should I pay a month?”
“Oh, forty-five or fifty is what I usually contribute. And then, if you
ever see any ice-cream or fruit or a new victrola record or anything
in that line, down-town, you just buy it and bring it home as an
occasional treat.”
Mauney sat back in his chair and smiled. There was a flush of
comfort in his face and a new relaxation. He liked the place,
although he was still overcome, almost exhausted, by the swift
changes of the day. Especially did he like Maxwell Lee, this
comforting fellow with visionary dark eyes who sat opposite him
now, smoking meditatively as if quite aware of the epoch-making
significance of a simple railway journey; as if he realized how great
an event it had really been to Mauney’s inexperienced soul.
CHAPTER II.
Mauney Prepares for College.
“I consider it most becoming and most civilized to mingle severity with good
fellowship, so that the former may not grow into melancholy, nor the latter into
frivolity.”—Pliny the Younger, Ep. Bk. 8.
When he awoke in the morning, he was vaguely conscious of
some one talking in the room. Over the edge of his counterpane his
eye caught the pyjama-ed figure of Lee, shaving in front of the
dressing-case mirror, and he soon realized that Lee was talking to
him.
“—thinking it over,” Lee was saying. “And I believe your best stunt
is to look up a tutor who will give you your matriculation work extra-
murally. That won’t tie you down to any formality of going to a high
school. You can work as hard as you like, and, at your age, you’ll
clean up that preliminary dope just like ice-cream.”
Mauney sprang out of bed and shaved. He fell in with Lee’s
suggestion and decided that he would look up a tutor that very
morning. He was thrilled with excitement and happiness. Outside the
windows, rain was splashing on the sills, but it was the merriest,
gladdest rain he had ever listened to. Before him stretched the great
adventure of education, rich in its promise of compensation for all
the years of miserable waiting. In fact, could it be quite true that he
was actually conscious? Was he not rather treading the air of a
delightful dream, from which, at any moment, he would awake to
bleak realities?
There were only three at the breakfast table when they descended
—Mrs. Manton, seated at the end in a rich dressing gown of yellow
silk, and Jolvin, with Stalton, at one side. The Englishman, fully
dressed as for business, ate in dignified silence. Stalton, whom to
know was to love, sat in his shirt sleeves without a collar, as if he
had no other business in life than to act in the capacity of a cross-
corner mentor for his landlady. Mauney was assigned to a place
between the two men, while Lee sat down at the opposite side.
“It’s a grand morning, Mr. Bard,” said Stalton, as he poured some
medicine into a spoon from a large bottle by his place. Perhaps,
thought Mauney, Stalton’s gray hair and flabby grey face were
evidence of some chronic ailment—the wearing effects of pain. He
felt sorry for his table companion.
“Hello,” laughed Lee, glancing across at the bottle, “What are you
taking now, Freddie?”
“This is a new consignment of dope, Max,” he replied good-
naturedly. “It’s guaranteed to contain the real wallop. Made up of
yeast, raisins, vitamines and monkey glands. Don’t be surprised to
see me challenging the heavy-weight champion next spring.”
Jolvin, whose mind at the moment may have been grappling with
serious business problems, was evidently irritated by Stalton’s
remark. Suddenly his face whirled directly about toward Mauney,
who nearly jumped with astonishment. “For God’s sake,” whispered
Jolvin, “I wish he’d stop that stuff at breakfast.” Then his head
snapped back to receive the last spoonful of his cornflakes.
“One would fancy,” he said aloud, “it would stop raining!”
“Yes,” murmured Stalton. “One would. But I guess there’s a few
bucketfuls left up there yet.”
“How’s the tooth this morning, Freddie?” enquired Miss Grote, as
she walked into the room.
“It’s still in my head, Sadie, but I expected it would jump out,
about two this morning.
“For God’s sake,” whispered Jolvin into Mauney’s ear; “he can’t
talk about anything, but teeth—teeth!”
He made a nervous stab at a rasher of bacon and cleared his
throat. “I fancy,” he said aloud, “we’ll be getting some prime weather
after this!”
“Yes, no doubt,” replied Stalton. “This rain ought to prime
anything, including the cistern pump.”
Mrs. Manton cast a reproving look at Stalton, shook her head
hopelessly, sighed, and continued her breakfast. Mauney, in the best
of spirits himself, unconsciously cast his sympathy with Stalton.
“Did you hear the rain on the roof last night, Mr. Stalton?” he
asked, by way of making conversation.
“Sure thing.”
“Did it help you to sleep?”
“It doesn’t affect me like that, Mr. Bard,” he answered.
“Unfortunately I passed through a period of my life when I had the
rain without the roof, and rain ever since brings up the past. And
then, in this kind of weather my teeth are always—”
“For God’s sake,” exclaimed Jolvin aloud, bolting from the table,
stamping indignantly into the hall, and presently banging the front
door behind him, as he left the house.
“What’s wrong with that long drink?” purred Mrs. Manton.
“He’s just acting natural,” Stalton said. “I knew he got out of bed
over the foot. He’s had more hard luck with his uncle’s estate in
England, too, and I knew he’d scoot if I said anything more about
teeth.”
“Well, he can tame himself,” Mrs. Manton submitted calmly. “This
is not an institution for the nervous, and if Jolvin doesn’t like it, he’ll
discover that there aren’t many invitations out to remain.”
“These fits of his are getting more frequent,” Stalton remarked.
“He’ll have to mix his drinks a little better than that anyhow,” said
the landlady. “Don’t you think so, Max?”
“It takes all kinds of people to make a world, Gertrude.” Lee
reminded her. “I feel so darned cut up about my biochemistry, I can’t
be expected to give an unbiased judgment.”
“Poor boy. You’ll get it, all right. When do you write?”
“This morning.”
Mauney accompanied his friend, whom he began to address now
as Max, down to the university and, after Lee had disappeared into
one of the buildings, stood thrilled by the spectacle before him.
Here, surrounding the square, reposed the exemplary specimens of
architecture that housed the various faculties. Max, in leaving, had
pointed them out hurriedly—medicine, industrial science, Methodist
theology, the great library, the convocation hall, the gymnasium, and
last, but most impressive, the arts building, a solid, reposeful mass,
as sure as learning itself, with its vine-dressed, dull grey walls of
stone, it’s turreted tower, its marvellous gothic entrance, leading
from the common day, past its embellished arch, into the dim
twilight of contemplation. The square was belted by a gravel road,
serving the various buildings, and was itself divided into eight
triangular lawns by wide cinder paths, crossing from side to side and
from corner to corner. It was a pleasant view, for the art of the
landscapist had relieved the conventionality of the pattern by maples
and ash-trees, distributed over the lawns, and by clusters of spiræa
and barberry set attractively at the edges of the paths. The square
was nearly deserted, save for one or two students who sat on the
benches reading.
Mauney wished that with the fall opening he could be ready to
enter upon his college course, but, knowing this to be impossible,
turned sadly away, but yet with burning ambition, to find the tutor
whom Max had recommended. He was discovered in a little office on
College Street, a small, withered individual, almost swallowed up in
the cluttered disorder of his administrative quarters. His yellow face,
creased like old parchment, bent into a mechanical smile as he
listened to Mauney’s desires. For a moment he fingered the paper-
knife on his desk, then cast a weary look at his young customer
through tarnished silver-rimmed spectacles.
“The matriculation requirements, Mr. Bard,” he said, in a cultured,
but infinitely dreary voice, as if repeating a stereotyped speech, “are
becoming increasingly onerous. The departments of the University of
Merlton have established rather severe standards for college
entrance, and I fear you will experience disheartening difficulties in
attempting to gain matriculation status within the limits of a single
winter term. However, your ambition is indeed commendable and,
with perseverance, combined with extra tutoring, you may perhaps
be able to succeed. The course that I would recommend”—he
reached for a folder and, opening it, ran his yellow forefinger down
its pages—“is partly a correspondence course, but partly, also, one
of personal supervision, especially in science subjects. The cost of
this course is considerable, but I am glad to be able to quote an
average of sixty per cent. successes over a period of the last fifteen
years. Other preparatory tutors have not, unfortunately, been able to
compete with these figures. The fees are payable strictly in advance,
and if you decide to embark upon the course, you are promised the
same individual, careful attention that is given to everyone.”
Mauney questioned nothing, but embarked. He was almost
delirious with happiness over the proceedings, the enrolment, the
purchase of a score of interesting books which the tutor
recommended, and the prospect of commencing so quickly the life
for which he had longed. His room at seventy-three Franklin Street,
next to Max’s, was soon a student’s den, with its own table, its own
volumes and its easy chairs. His life became a very pleasant thing,
for, with his daily visits to the little office on College Street, and the
diversions of the boarding house, he found what seemed to him a
wealth of variety. He was astonished at his own contentment and at
the self-sufficient quality in him that scarcely, if ever, caused him to
think of his former home, or to reflect upon the dearth of relatives in
his new existence. He wrote to his aunt in Scotland, expressing high
satisfaction with his present occupations. He settled down in the
loved quietness of his room, to master the rudiments of education.
Never once did he stop, weary, for with the sharp appetite of a
starved mind, he thought of nothing but more information, and
more.
Max, who had been successful in his supplementary examination
and was now engaged in the fourth year of his medical course,
frequently dropped into Mauney’s room for a smoke and a chat. Max
never spoke about his own home, and Mauney refrained from
questioning him. The basis of their friendship was something
personal and gloriously indefinite, that neither thought of analyzing.
They felt at home with each other, and never, from the very
beginning of their acquaintance, did anything disturb this quite
unaccountable understanding. Mauney always felt that there was a
hidden thought at the centre of Max, with which some day he would
be favored, for behind his dark and often weary eyes great dreams
seemed to pass, greater than the drawl of his clever and sarcastic
tongue. He ventured to think that perhaps Max had drifted into a
profession for which his nature disqualified him, for he naturally
gained the impression that a medical student needed to be, in one
particular sense, a feelingless person, with certain vulture-like
qualities to steel him against the revoltingly physical aspects of his
work. The skull in Max’s wardrobe, the illustrations in his books—
there were many symbols of the idea. In secret, however, Max was
evidently no materialist, but sought the wide comfort of philosophic
generalities. No one, to be sure, would suspect it at seventy-three
Franklin Street, where he was known by his smile, but Mauney
would catch the plaintive note in some quiet remark, as when one
evening, in discussing college work in general, he said:
“Wrap up your colleges and throw them in the ocean. They furnish
us a few years of diversion, but after that there’s life, and, strange to
relate, Mauney, my son, they have not prepared us for that.”
Mauney excused such criticisms of the university on the basis of a
personal warp in Max’s character, forgave him for what seemed a
vandal attitude, and went on believing more firmly than ever in the
light that spread from the lamp of learning. By its flame, comforted
and inspired, he forgot the passage of time. He failed to notice the
blush of late autumn that swept like a passion over the trees of the
city, scarcely saw their bare arms raised in supplication to the
greying skies, nor heaven’s response of swift winds carrying fleecy
burdens. Not until the firm banks of snow began to settle down,
smaller and smaller, under the warming suns of a windy March, and
energetic streams of murky water rushed along the street gutters,
did he wake from his steadfast dream to realize that his term was
nearly over. Then came a sharp bout with the examinations and at
the end of May he stood looking curiously down at the withered old
tutor who was smiling less stiffly, less professionally, than usual.
“I am pleased to tell you,” he said, “that you have gained your
university entrance standing. Your work with me in the preliminary
subjects has been, to say the least, good, and it will afford me
pleasure to produce documentary evidence of your success.” He
paused to reach a small certificate from a drawer. “This,” he
continued, handing it to Mauney, “should be carefully preserved and
forwarded to the university in making your application for admission
thereto, sometime before September.”
“Thanks.”
“And before you go,” said the tutor, rising stiffly from his chair, “let
me express the pleasure I have had in overseeing your early
academic career. Moreover, I would be interested to learn what
particular course you contemplate taking at the university.”
This was a new idea to Mauney. He looked at the instructor for a
moment, with a perplexed expression.
“I’m much interested in people,” he said, “and I think if I could get
a course in history it would suit me.”
“Remember,” cautioned the old man, lifting his finger as if
admonishing a wayward son, “history is a culture course which, from
the financial standpoint, leads you nowhere. It would fit you only for
teaching, a profession which, as I have learned from acrid
experience, is not perfectly appreciated by the public. You have
other courses to choose from, the more practical ones, as they might
be called, such as engineering, law, medicine.”
“Well, I’ll have to consider the question,” Mauney replied.
“Just so. In the meantime, I would be glad to advise you on any
points and to see you, from time to time, in order to learn of your
academic progress.”
There was a light almost of kindness in the wrinkled, yellow face
as he bade him good-bye. Mauney did not know how seldom that
light had been there under similar circumstances, nor did he know
that the affection of the old tutor was the same kind of affection that
he unconsciously inspired in most of his associates. Burning with
gleeful happiness over his success, he hurried home to tell Max.
“Well, you old bear!” exclaimed Lee, violently shaking Mauney’s
hand on learning the news. “You couldn’t have done better. I’m as
happy as if I’d done it myself.”
“Behold the hero,” Max said, as they went into supper together.
“He’s just laid ’em all out. Four years’ work in one.”
“Hurrah!” shouted Mrs. Manton, putting her arms about Mauney’s
neck and kissing him prettily on the cheek. “I knew you’d do it,
Mauney,” she said.
“Maybe you did, Gertrude,” he laughed, trying to cover his
embarrassment, “but I didn’t expect that. However, don’t think I
didn’t like it.”
Even though Mrs. Manton’s impulsive embrace was decidedly
consoling, Mauney nevertheless disliked it. He felt immediately
afterwards that he would increase his diligence to detect her next
time before it was too late. He accused himself of being perhaps by
nature too cold. But from the evening, some years since, when he
had felt a woman’s hand upon his own, he had disliked the feeling. A
woman’s hand was too soft. It reminded him unavoidably of a snake,
and made him shiver. This thesis ran through his private thoughts a
good deal. He did not know women. He thought they were rather
pleasant beings at times, but the danger of having their warm, soft
hands suddenly upon him, inspired an attitude of caution. He felt
confident of managing them in conversation, but confidence flew to
the winds at the approach of hands, or arms, to say nothing of lips.
The summer months passed with snail-like tardiness. Having no
place in particular to go, and nothing in particular to do, he
remained in Merlton at his boarding house, and divided his time
between reading and making excursions on foot, exploring the city.
He now seized his first opportunity to gratify a long desire, and
spent many of his mornings on the river. Max, who had this time
passed his annual examinations without stars, had gone out west to
teach school for the summer, in order to make enough money to
finance his final year in medicine. The balance of the personnel at
the boarding house remained unchanged, until one morning at
breakfast he learned that Jolvin was about to return to England. The
news came from Stalton, who said he had been talking to Jolvin the
night before.
“Gertrude,” he said, “do you know what’s happened to that bird?
He’s fallen into a big estate—his uncle’s estate. Why, it’s worth a
couple of hundred thousand. I saw the lawyer’s letter last night.
What do you know about that?”
Mrs. Manton ate in silence for a moment. “Do Jolvin’s socialistic
beliefs prevent him from accepting it?” she asked.
“Not very much!” Stalton replied with sarcastic emphasis. “And, by
the way he was talking last night, he’s forgiven England for being
such a dough-headed outfit. Why, that fellow came out here two
years ago like an understudy of Columbus. England? Not if he knew
it. And now I’ll bet he gets the first boat home. Just watch him
skidaddle.”
It was not many minutes until Jolvin, the centre of conversation,
came down to breakfast, unusually smart, his face wreathed in
smiles.
“Good morning, people!” he said expansively, with a very full bow.
“Isn’t it a lovely morning? Good-morning Stalton!”
“How do you do?” said Stalton crisply.
After taking his seat, the Englishman, noticing the silence of the
table, thought perhaps to stir up conversation.
“You know,” he began, glancing at his dish, “these corn-flakes are
really beastly grotesque things. In England one scarcely sees them.
They are, I fancy, an expression of American commercialism which
invades even the time-honored ritual of breakfast.”
Stalton suddenly dropped his spoon on the table.
“Well, I’m damned,” he said, simply, and once more took up his
spoon, having received a stern look from Mrs. Manton.
Jolvin appeared not to have heard Stalton’s remark, but continued,
“But, of course, America is too busy to cook porridge. There is no
leisure or time for what one might call a comfortable dignity.”
“All this don’t jibe very well with what you usually say about
England,” Stalton remarked. “Most of the time you seemed to hate
the word.”
“Not at all,” argued Jolvin. “Any criticisms I have ever made of
England were meant most heartily. But they were criticisms, not
blasphemies. If I were indifferent to England, I should never bother
even to criticize.”
“Have it your way, Jolvin,” said Stalton. “But you were always
damning the leisure class. Now you’re praising them.”
“I still damn them for their faults. Why, then, should I not praise
them for their virtues?”
“Sail right ahead,” invited Stalton. “You’re in good form this
morning. Got me outclassed, that’s a cinch.”
Even without Jolvin the place was still a most unusual boarding
house. Mauney had learned, by this time, some of its tacitly-
established principles. In the first place Mrs. Manton, at thirty-five,
being widowed as was understood, regarded her house as a master
hobby. Great attention was bestowed upon the furniture, the rugs
and the walls. She wanted her guests to be comfortable and, to that
end, would put herself about unceasingly. No advertising of vacant
rooms was ever done, for it was better to have an empty room
without a monthly revenue, than a full room with an unknown,
undesirable stranger. Certain standards had to be satisfied. Mrs.
Manton’s boarders had to possess what she tersely designated as
“savez.” This meant a number of things. It meant the faculty of living
in harmony with other boarders, of being informally polite and not
impolitely formal. It meant keeping in the background all grandiose
ideas, but at the same time indulging in enough conversation to
register one’s consciousness. It meant that one should not comment
upon the doings of others, but at the same time that one should
avoid doing anything to invite comment. It meant even this, that if
one’s breakfast were not placed before him as quickly as desired, he
was expected to go to the kitchen and get it; or if one’s bed was not
made up, the understanding was that it be made up by oneself. And
finally, of course, that after a few days’ residence as an introduction,
one would notice that the landlady was to be addressed familiarly as
“Gertrude.”
Mrs. Manton preferred men to women boarders. Mrs. Dixon was
permitted because her husband was a good sort, with funds of
information about racing horses and the track in general. Sadie
Grote, a stenographer down town, was agreeable and sweet, very
unselfish and therefore helpful. Women had often been under
consideration. At one time Mrs. Manton conducted an experiment by
letting the whole top flat to four university girls. They remained a
whole term, but when the last of their baggage had left the front
door in the spring, Mrs. Manton had turned to Stalton with all the
impatience of a disappointed experimenter.
“Freddie,” she had vowed, “never again! If we ever have girls,
they’ve got to have blood in their veins, not pasteurized milk. Isn’t it
pitiful how that dreadful disease known as brain-wart seems to get
them.”
There was no gainsaying it—eligibility to seventy-three Franklin
Street required unusual, indescribable qualities. If Mrs. Manton had
written down rules of conduct (which, of course, she never did), and
hung them on the wall, they would have read much as follows:
“1.—Avoid extremes.
“2.—Nourish high-falooting ideas, if you wish, but keep
them under your hat.
“3.—Be as happy as you choose, but don’t explode
with nauseous hilarity, since somebody else may
be sad.
“4.—Be downcast when you must, but don’t spread
your gloom.
“5.—Be erudite, but don’t teach your ideas.
“6.—Be chuck-full of anything you choose to be chuck-
full of, but sit on it.
“7.—Remember that seventy-three aims at averages,
prefers neutral tints and the soft pedal.
“8.—Don’t effervesce—most of us have passed that
stage.
“9.—Don’t criticize—we all have to live.
“10.—Live, but don’t plan. To-day was to-morrow,
yesterday.”
Mauney felt unlikely to transgress many of these tacit rules of
conduct. He was quiet enough in disposition to melt into the quiet
shadows of the place, and was fond enough of the inhabitants to
pattern his superficial manners after theirs. But he well knew that
there was danger of breaking one of the rules. He had not yet
passed the stage referred to in number eight, and was quite liable to
burst forth enthusiastically to some one. His enthusiasm for his
books and the sheer happiness he obtained from them was
dangerously concealed. It troubled him. He wanted to talk to Max
Lee, and longed for his return. Then, too, the present, though
charming, was so incomplete! The others at the boarding house truly
lived for the present moment, but Mauney was feeling the great
future beating like a pulse. He was standing like a benighted sailor
on the dark coast, feeling the break of waves he could not distinctly
see, and coveting the dawn when all would be revealed.
CHAPTER III.
The Other Half of the Class.
“A morning sun, and a wine-bred child and a Latin-bred woman seldom end
well.”—Herbert’s Collection.
Mauney met Lorna Freeman the first day of college. He did not
know her name at first, but she impressed him. This was partly
because certain grooves, instituted that day, promised to guide her
in his company for the next four years, brilliant in prospect. It
happened that out of the great University of Merlton, only two first
year students had chosen the “straight” history course. Many others
had elected to take combined courses of history plus something else
or other, but of the entire academic population of the first year only
two showed the real specialist thirst for history alone. This meant
that they would receive much that the others would not. They would
be inducted more deeply into the records of human development.
They would be together, a class all by themselves, at times,
penetrating further than the dilettanti, who stopped with
constitutional history of Germany. For these two out-and-out
students there would be interesting journeys afield.
He faced Lorna Freeman, therefore, with at least the vague
knowledge that they two were the real, serious history class. They
enrolled together with the assistant professor of history, Dr. Alfred K.
Tanner, M.A., Ph.D., D.C.L. (and other degrees usually taken for
granted), in his particular upstairs office in one of the wings of the
Arts Building. Miss Freeman had already submitted her name, just as
any other student might have done, although there were reasons, as
shall be seen, why it was superfluous. There were a score of
students outside Dr. Tanner’s door, waiting to be enrolled. But they
were the part-timers, the non-specialists, the great unwashed. First
attention must be given to the “straight” students, and Alfred Tanner
had already given his attention to Lorna Freeman, had waved her to
a stiff chair by the mullioned windows, and was now giving his
attention to Mauney.
He was a big, energetic figure, even as he sat behind his flat-
topped desk, with a look of keen awareness mixed with love of his
work. He was grey, and bald, and hugely present. He leaned
forward, gesticulating, snapping his grey eyes eagerly.
“Your name is what?” he asked.
“Bard.”
“Bard, yes, Bard. What else?” he mumbled, as he wrote it down.
“Mauney.”
“Mauney, yes; Mauney Bard! I see!” he looked up to subject
Mauney to a severe scrutiny, during which he was absent-mindedly
biting the nail of his little finger.
“And now, tell me, Mauney Bard,” he said suddenly, aiming his
plump forefinger at his new pupil, “Tell me, as well as you can—
that’s to say offhandedly—tell me exactly why you elected the
straight history course?”
As he waited for an answer, he looked frowningly toward the
window, rubbed his nose, and held his head like a musician
preparing to judge the quality of a chord of music.
“I would say the reason is simple enough,” said Mauney.
“Good,” commended Tanner, hammering the desk with his fist:
“Simple enough? Yes? Good. All right, Bard; explain that. Tell me
exactly why you elected it?”
“Because,” said Mauney deliberately, “I’ve always wanted to
understand the basic principles of human progress.”
Tanner, still frowning at the window, mumbled in an absent-
minded tone: “‘Basic principles of human progress.’ Yes; basic
principles.” Then, turning suddenly toward Mauney, he once more
aimed his finger like a pistol at his face, while his voice came out
with great clearness and deliberation: “Good for you. That’s good,
Bard, very good. Now, you will consult your time-table to find out
your classes, and, by the way, it’s a very small class this year.” He
turned toward the young lady seated by the window.
“Lorna!” he said.
“Yes! Uncle Alfred,” she responded, in a clear voice, rising and
gracefully approaching the desk.
“This is Mauney Bard—Miss Freeman!”
“How do you do,” she said, with a faint smile and a nod of her
head.
As Mauney bowed to her he noticed what clear, blue eyes looked
fearlessly into his—calm, quiet eyes, with almost a suggestion of
challenge. She was in a grey street costume that clung neatly to her
spare, trim form, and wore a wide-rimmed black hat that sat smartly
upon her blonde hair and emphasized the natural pallor of her face.
Her features were regular—a straight, refined nose, and thin, pretty
lips. Her hands were extremely white. In different attire she could
have played a part in a tableaux of the vestal virgins. She gave
Mauney the same feeling as he had often experienced on looking
across the meadows in the white light of a dewy dawn.
“You and Mr. Bard are the class,” laughed Dr. Tanner. “I hope that
a friendship of reasonable rivalry may exist in the class, at all times,
and that we will be able to find a room somewhere small enough to
hold us.”
“I know a good place, Uncle Alfred,” said Miss Freeman.
“Where, then?”
“In the tower.”
“Well, we shall see, Lorna. We shall see. I don’t like it myself, but
your suggestion merits consideration. H’m! The tower? Why on
earth, my dear child, do you say the tower?”
“It isn’t in use.”
“No. Neither is the furnace room.”
“But the tower would give one such a philosophical elevation, just
like old Teufelsdrockh in Carlyle’s book.”
“Oh, damn Carlyle!”
“Uncle Alfred!”
“Excuse me, Lorna,” he laughed mischievously. “Well—a place will
be found. Now, you two, clear out. There’s a congregation of
pilgrims near by, seeking the shrine of Magnus Apollo.”
Mauney did not know that the young lady with whom he walked
down the worn stone steps of the history department was the
daughter of Professor Freeman of that same department, whose
office they passed on their way to the square. That was to be
learned later. He only knew that she seemed an exceptionally fine
person.
“Isn’t it funny,” he remarked, as they passed through the long
corridor of the Arts Building. “That there should only be two of us in
the class.”
“No, I don’t think it’s funny,” she said.
“I mean remarkable,” he corrected himself.
“Well, it’s a small class, certainly,” she admitted. “There are few
people who elect history as a straight course in Merlton, I believe.
There should be more. I had wished there would be at least another
woman.”
“That would have made it pleasanter for you, Miss Freeman.”
“Naturally.”
Mauney noticed how little deference her manner contained. After
he had left her at the front entrance and was on his way home, he
wished that she had said: “Oh, I think we’ll get along all right.” But
she had frankly admitted that another woman in the year would
have made it pleasanter for her. Queer little blaming thoughts rose
up in his mind against her. Then his thoughts changed. He began to
admire her attitude. She had been absolutely frank. Was that not
rather unusual? Was she not an unusually truthful kind of girl?
Presently he lost all touch with the argument. His brain was
painting pictures of her, in dignified poses, representing some
abstract idea of virtue. Finally he checked the images and cursed
himself for being such a susceptible person. Miss Freeman was
merely a member of the class. Half the class had no right to be
thinking such thoughts of the other half.
Nevertheless Mauney’s first impression of university life was an
impression of a woman, the first woman, in fact, who ever seriously
disturbed his thoughts. That night he went into Max Lee’s room to
have a smoke. Max was tired after his summer of teaching, and was
viewing the fifth and last year of his course with evident distaste.
“Sit down, Mauney, my son,” he invited. “There’s some good
cigarettes. I’m glad you’re taking to smokes. It will make things
evener between us. Well, how’s things?”
“Not bad, Max,” he replied, taking one of the easy chairs. “I got
enrolled to-day, but haven’t seen much of the university life yet. The
assistant professor of history, Dr. Tanner, is a good fellow. I’m going
to like him. He’s got a big-brotherly sort of way with him, and I hope
he lectures to us. I didn’t see the professor yet. I suppose he’s too
important for a mere first-year man to meet so soon.”
“How many are in your group?”
“Just two. Myself and a young lady, whom I met this morning in
Tanner’s office. Her name is Freeman—rather a good-looking person.
She and I are apparently booked up together for a four-years
voyage.”
“In that case,” smiled Max, “I hope she’s companionable.”
“Well,” he replied very seriously, “that’s doubtful. I wish there was
another man along—somebody I could swear at when I felt like it.
I’ll make the best of it. She may be a really fine person. She’s a
niece of Tanner’s, too. When do you start work?”
“To-morrow. Fifth year is pretty easy, but I wish it was over. I’m
getting sick of the whole game.”
“What’s the matter?”
“Money, of course.”
“Do you mean you’re short of cash?”
“Sure. It’s going to be tough wiggling to get through this year,” he
admitted. “Do you know, lack of money is the one, big, damned
tragedy of my life?”
“Could I lend you some?” Mauney asked simply.
“Could you—what?” exclaimed Lee, sitting up. “Have you got
money?”
“Some,” admitted Mauney. “I could lend you a few hundred, if you
need it.”
“It’s mighty decent of you, boy,” Max said. “But I couldn’t accept
it.”
“You don’t need to feel that way.”
“But I do nevertheless. No, I couldn’t. That’s all.”
“Will you promise to let me know if you need it, later?”
“Look here,” said Lee, settling back in his chair wearily. “I
mentioned money only to dismiss the topic. I have no desire for
wealth, and it’s not immediate needs I’m thinking of. But here I am,
fagged, at the start of my last year. When I get my M.D. I’ll be as far
from making money as I am now. It’s getting to be an up-hill game,
you see? There are certain things that a fellow wants to do some
time before he dies, and getting married is one of them.”
“Yes,” said Mauney; “I suppose that comes into the scheme of
things.”
“The scheme of nothing!” scoffed Lee. “It simply gets into your
blood when you meet the right woman.”
“Am I to suppose,” asked Mauney, in a teasing tone, “that you
have met her?”
Lee was silent. His dark eyes were seriously looking into space,
while his cigarette burned slowly between his fingers. Mauney
realized that he had trampled carelessly on holy ground, but allowed
his own silence to be his only apology.
“We’ve known each other long enough, Mauney, to understand
how things affect us individually. I’ve never mentioned women to
you. But there has been one, all along—this past year. She’s real. I
love her, but I can’t tell her. She regards me only as a friend, and I
wouldn’t let her know how I feel for anything.”
“You may wonder why I wouldn’t,” he continued. “Well, it’s like
this, I’ve made up my mind to go into research work next year, if my
health remains good, and that kind of work won’t give me a living,
let alone enable me to marry. She’s a girl who deserves happiness.
Some one else will give it to her—not me.”
“But the future may be brighter than you think, Max.”
“I’m not a pessimist, Mauney,” he said thoughtfully, leaning his
head away back and closing his eyes. “I keep up a cheerful front
most of the time. But I know—I simply know that I’ll never marry
Freda MacDowell.”
“What is she like, Max?”
“I’ll have you meet her some time. She’s just like nobody else.”
The opening days of college dragged slowly for Mauney. There
were broken classes, time-tables not yet perfected, initiations and
other interfering details. Then, as if suddenly, the great university
wheel quivered to a start and immediately swung around with
remarkable smoothness and astonishing rapidity. In the daytime he
sat listening to interesting lectures. In the evenings he lived with his
books, deeply absorbed, as the weeks passed, with the problems of
history. The records of human progress drew him with a warm,
romantic attraction, for his imagination filled in the gaps that make
history different from story. Characters became real and living. He
rose and fell in sympathy with the dim fortunes of forgotten men.
The formal page, with its caption and its paragraphs, faded into
invisibility, leaving a glowing passage of actual life in which he
brought himself temporarily to live.
It was very engrossing. Lorna Freeman found it so, too. She grew
somewhat more friendly as the weeks passed, and by mid-term she
would talk volubly with Mauney on historical subjects. He found her
mind to be an acutely exacting one. It surprised him at first to
discover such a mind in a woman. He thought her mental powers
exceeded his own, because she could nearly always trip him up in an
argument, a thing which she habitually did without exultation, but
just methodically, as if tripping him up were part of her natural
occupation. One day he learned that her father was Professor Robert
Freeman, the seldom-seen head of the department. Mauney only
saw him once, as he was pointed out walking thoughtfully through
the corridors, a small, shrewd-appearing man, with grey eyes and a
fixed smile.
History was absorbing, but our young hero was finding himself a
good deal in thought about Lorna Freeman. Not once had he ever
said a thing even faintly familiar. One Monday morning, however, the
temptation became unduly strong. Miss Freeman was seated in the
seminary room by the long table, waiting for Dr. Tanner to take the
class. It was winter, and her fur coat was laid neatly over the back of
an empty chair. She never removed her hat, a prerogative gained
from the intimate size of the class. As Mauney entered the room she
looked up from a book and nodded.
“Good morning,” he said, as he took a chair at the opposite side of
the table. The large Gothic window at the front of the room
commanded a view of the square, busy with students hurrying in
various directions to their lectures. Dr. Tanner was late. They sat for
fully a quarter of an hour, she quietly reading, Mauney stealing
occasional glances at her pensive face. He tried to categorize Lorna
Freeman, but could not. She did not fit into any types existent in his
mind. She was definitely unusual. She attracted him on this account.
There was also about her a certain queenliness. Why had they never
once found anything to talk about except their work?
“I guess Dr. Tanner has been waylaid,” he ventured at length.
“He’s usually so punctual, too,” she replied, and then continued
reading.
“Do you ever get tired of studying?” he went on, determined to
sound her.
“Well, naturally. Don’t you?”
“I certainly do. I suppose if there was another man in the class I
wouldn’t mind it so much.”
She glanced quickly up.
“Mind what, Mr. Bard?”
“Well, you see, Miss Freeman, perhaps there’s something else in
life besides continual study. I’d like to have somebody to chew the
rag with, once in a blue moon.”
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com
Ad

Recommended

Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
matbarnargis59
 
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
Programming iOS 5 2nd Edition Matt Neuburg
Programming iOS 5 2nd Edition Matt Neuburg
saertahai
 
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
quizaloan
 
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
dhentyimeng51
 
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
lindzpeccoo
 
Ios 5 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 5 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
colffwalbum
 
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
ericasapna10
 
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Reinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
heddaraduson
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
pundaiarleny
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
bambildurdle
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
laczaididdle
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
nieysaiotti
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
lalikaukpono
 
Hello world ios v1
Hello world ios v1
Teodoro Alonso
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
batyegrocez1
 
iPhone in action introduction to Web and SDK development 1st Edition Christop...
iPhone in action introduction to Web and SDK development 1st Edition Christop...
lipiriuezee
 
Objective C Fundamentals 1st Edition Christopher Fairbairn
Objective C Fundamentals 1st Edition Christopher Fairbairn
mitclxlt
 
iPhone Workshop Mobile Monday Ahmedabad
iPhone Workshop Mobile Monday Ahmedabad
momoahmedabad
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Ios development training presentation
Ios development training presentation
Deepak S
 
Dev101
Dev101
konnis
 
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
Blend Interactive
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 

More Related Content

Similar to Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman (20)

Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Reinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
heddaraduson
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
pundaiarleny
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
bambildurdle
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
laczaididdle
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
nieysaiotti
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
lalikaukpono
 
Hello world ios v1
Hello world ios v1
Teodoro Alonso
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
batyegrocez1
 
iPhone in action introduction to Web and SDK development 1st Edition Christop...
iPhone in action introduction to Web and SDK development 1st Edition Christop...
lipiriuezee
 
Objective C Fundamentals 1st Edition Christopher Fairbairn
Objective C Fundamentals 1st Edition Christopher Fairbairn
mitclxlt
 
iPhone Workshop Mobile Monday Ahmedabad
iPhone Workshop Mobile Monday Ahmedabad
momoahmedabad
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Ios development training presentation
Ios development training presentation
Deepak S
 
Dev101
Dev101
konnis
 
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
Blend Interactive
 
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Reinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
heddaraduson
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
pundaiarleny
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
bambildurdle
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
laczaididdle
 
Learning Swift 3 Early release 3rd Edition Jonathan Manning
Learning Swift 3 Early release 3rd Edition Jonathan Manning
nieysaiotti
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd...
lalikaukpono
 
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning
batyegrocez1
 
iPhone in action introduction to Web and SDK development 1st Edition Christop...
iPhone in action introduction to Web and SDK development 1st Edition Christop...
lipiriuezee
 
Objective C Fundamentals 1st Edition Christopher Fairbairn
Objective C Fundamentals 1st Edition Christopher Fairbairn
mitclxlt
 
iPhone Workshop Mobile Monday Ahmedabad
iPhone Workshop Mobile Monday Ahmedabad
momoahmedabad
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Ios development training presentation
Ios development training presentation
Deepak S
 
Dev101
Dev101
konnis
 
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
"Intro to iOS Development" - Derek Fernholz, South Dakota Code Camp 2012
Blend Interactive
 

Recently uploaded (20)

THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Ad

Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman

  • 1. Get the full ebook with Bonus Features for a Better Reading Experience on ebookgate.com Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Goodman https://ebookgate.com/product/learning-the-ios-4-sdk-for- javascript-programmers-create-native-apps-with-objective-c- and-xcode-1st-edition-goodman/ OR CLICK HERE DOWLOAD NOW Download more ebook instantly today at https://ebookgate.com
  • 2. Instant digital products (PDF, ePub, MOBI) available Download now and explore formats that suit you... Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Objective C and Xcode 1st Edition Danny Goodman https://ebookgate.com/product/learning-the-iphone-sdk-for-javascript- programmers-create-native-apps-with-objective-c-and-xcode-1st-edition- danny-goodman/ ebookgate.com iOS 12 App Development Essentials Learn to Develop iOS 12 Apps with Xcode 10 and Swift 4 Neil Smyth https://ebookgate.com/product/ios-12-app-development-essentials-learn- to-develop-ios-12-apps-with-xcode-10-and-swift-4-neil-smyth/ ebookgate.com iOS 9 SDK Development Creating iPhone and iPad Apps with Swift 1st Edition Adamson https://ebookgate.com/product/ios-9-sdk-development-creating-iphone- and-ipad-apps-with-swift-1st-edition-adamson/ ebookgate.com Beginning IOS Storyboarding with Xcode Lewis https://ebookgate.com/product/beginning-ios-storyboarding-with-xcode- lewis/ ebookgate.com
  • 3. Pro Objective C Design Patterns for IOS 1st Edition Carlo Chung https://ebookgate.com/product/pro-objective-c-design-patterns-for- ios-1st-edition-carlo-chung/ ebookgate.com Learning Cocoa with Objective C 4th Edition Paris Buttfield-Addison https://ebookgate.com/product/learning-cocoa-with-objective-c-4th- edition-paris-buttfield-addison/ ebookgate.com JavaScript for Programmers 1st Edition Paul J. Deitel https://ebookgate.com/product/javascript-for-programmers-1st-edition- paul-j-deitel/ ebookgate.com Learn Unity 4 for iOS Game Development Create amazing 3D games for iPhone and iPad 1st Edition Philip Chu https://ebookgate.com/product/learn-unity-4-for-ios-game-development- create-amazing-3d-games-for-iphone-and-ipad-1st-edition-philip-chu/ ebookgate.com Learning Mobile App Development A Hands on Guide to Building Apps with iOS and Android 1st Edition Jakob Iversen https://ebookgate.com/product/learning-mobile-app-development-a-hands- on-guide-to-building-apps-with-ios-and-android-1st-edition-jakob- iversen/ ebookgate.com
  • 7. Learning the iOS 4 SDK for JavaScript Programmers
  • 9. Learning the iOS 4 SDK for JavaScript Programmers Danny Goodman Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
  • 10. Learning the iOS 4 SDK for JavaScript Programmers by Danny Goodman Copyright © 2011 Danny Goodman. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editors: Andy Oram and Brian Jepson Production Editor: Holly Bauer Copyeditor: Amy Thomson Proofreader: Kiel Van Horn Indexer: Ellen Troutman Zaig Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: December 2010: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning the iOS 4 SDK for JavaScript Programmers, the image of a King Charles Spaniel, and related trade dress are trademarks of O’Reilly Media, Inc. 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 O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-38845-4 [LSI] 1291233444
  • 11. Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Why Go Native? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Using an App Offline 2 More Access to the Hardware 3 More Access to the Software 4 What You Lose 6 Distribution 7 Apple iOS Developer Program 8 Content 8 Authoring Platform Choices 8 Taking the Plunge 9 2. Welcome to the iOS SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Hardware and OS Requirements 11 Installing the SDK 12 About iOS Developer Programs 12 Inside the SDK 14 Viewing Developer Documentation 15 Loading Code Samples 18 Setting the Project’s Base SDK 21 Trying the iOS Simulator 22 Coming Up... 24 3. Creating a Test Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Creating the Project in Xcode 26 Selecting a Project Type 26 Naming and Saving the New Project 29 Welcome to Your Project 29 Editing Your First Files 31 What the runMyCode: Method Does 34 v
  • 12. Building the User Interface 35 Adding a Button to the View 38 Connecting the Button 42 Going for a Test Ride 46 Congratulations 49 4. Structural Overview of an iOS App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Where It All Begins: APIs 51 APIs You Already Know 51 The Cocoa Touch APIs 52 Frameworks 53 Foundation Framework 54 UIKit Framework 54 CoreGraphics Framework 55 Adding Frameworks 55 Frameworks Set in Stone 56 Welcome to Class Files 57 The JavaScript Way 57 The Objective-C Way 58 Header File Details 61 Using Xcode to Create DGCar Class Files 65 Editing the @interface Section 68 Message Passing 70 Editing the @implementation Section 70 Integrating the DGCar Class into Workbench 75 Creating Object Instances 76 NSLog() and String Formats 77 Running the Code 78 What About Accessing Instance Variables? 79 Recap 81 5. App Execution Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Some C Language Roots in an iOS App 83 An Introduction to Delegates 85 How UIApplication Appoints Its Delegate 87 The App’s Info.plist File 87 Inside MainWindow.xib 88 iPhone App Development Design Patterns 92 The Model-View-Controller Design Pattern 92 Other Design Patterns 94 The Importance of Views 95 The App Window—UIWindow 96 Adding Another View to Workbench 97 vi | Table of Contents
  • 13. Recap 106 6. Central Objective-C Concepts: Pointers, Data Types, and Memory Management . . 107 Pointers 108 Pointers and Memory 108 Pointers and Objective-C Variables 110 Pointer Notation 111 Determining Pointer Usage 113 Data Typing 115 Objective-C Data Types 116 Cocoa Touch Data Types 116 Objective-C Variable Declarations 118 Objective-C Method Declarations 118 The id Data Type 122 Converting Objective-C Data Types 123 Memory Management 125 Cleaning Up After Yourself 125 The Retain Count 127 Autorelease Pools 129 Observing Memory Usage 130 Recap 131 7. C Language Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Variable Names 133 Variable Scope 136 Instance Variables 137 Local Variables 137 Local Variables in Control Structure Blocks 138 Static Local Variables 140 Global Variables 140 Constant Values 141 Functions 142 C Structures 148 C Arrays 151 Enumerated Types 152 Operators 153 Program Flow Constructions 153 Boolean Values 154 Math Object Equivalents in C 155 Inserting Comments 157 Recap 157 Table of Contents | vii
  • 14. 8. Objective-C/Cocoa Touch Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 More About Classes 159 Temporary Objects 160 Subclassing Framework Classes 161 Defining Your Own Custom Subclasses 162 Adding to a Class Without Subclassing—Categories 166 Real Classes in Real Action 168 TheElements Overview 168 TheElements Class File Structure 171 Class Properties 175 Specifying Properties in the Header File 176 Synthesizing Properties in the Implementation File 178 Using Properties 178 Properties in Framework Classes 180 About NSString 181 Creating an NSString 182 JavaScript String Method Equivalents in Objective-C 185 NSMutableString 189 About NSArray 190 Creating an NSArray 192 Retrieving Array Elements 193 JavaScript Array Method Equivalents in Objective-C 193 NSMutableArray 194 About NSDictionary 195 Creating an NSDictionary 195 Retrieving Dictionary Entries 197 NSMutableDictionary 198 Arrays and Dictionaries in Action 199 Recap 202 9. Common JavaScript Tasks in Cocoa Touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Formatting Numbers for Display 203 Preformatted Number Styles 204 Rounding Numbers for Display 206 Creating a Date Object 207 Adding a UIDatePicker to Workbench 207 Understanding NSDate 210 Creating a Date Object for a Specific Date 211 Extracting Components from an NSDate Object 213 Creating NSDate Objects from Strings 214 Converting an NSDate to a String 217 Calculating Dates 219 10 Days in the Future 219 viii | Table of Contents
  • 15. Days Between Dates 220 Comparing Dates 221 Downloading Remote Files Asynchronously 222 Example Project 223 Creating the Request 224 Initializing the NSMutableData Object 225 Delegate Methods 226 Downloading Only When Needed 228 Accounting for Fast App Switching 231 Reading and Writing Local Files 233 iOS App Directories 233 Obtaining Directory Paths 235 Obtaining Paths to Files Delivered with Your App 236 Writing Files to Disk 236 Reading Files from Disk 238 Writing and Reading Property List Files 239 Performing File Management Tasks 240 Sorting Arrays 241 Sorting with a Selector 241 Sorting with a Function 243 Sorting Arrays of Dictionaries with NSSortDescriptor 245 Capturing User-Entered Text 246 The Code Portion 247 The Interface Builder Portion 250 Validating Text Entry with Regular Expressions 251 Modifying the Code 253 Modifying the User Interface 255 Using Regular Expressions for Text Search and Replace 255 Dragging a View Around the Screen 258 The Code Portion 259 The Interface Builder Portion 264 Recap 265 A. Getting the Most from Xcode Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 B. Common Beginner Xcode Compiler Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Table of Contents | ix
  • 17. Preface You don’t have to be an Apple fanboy or fangirl to give Apple Inc. credit for redefining mobile gadgetry and its surrounding industries. First the company used the iPod to reshape the music industry and strongly influence how we acquire and consume tunes. Just count the number of people wearing iPod-connected earbuds in a subway car. Then the iPhone rewrote the cellular telephone industry manual, while opening the world’s eyes to the potential of being connected to the Internet nearly everywhere, all the time. It’s happening again with the iPad, where electronic publishing is evolving right before our eyes. Although the iPhone was an early success with just the workable but limited set of Apple-supplied applications that came with the phone, programmers couldn’t wait to get their hands on the platform. The first word that Apple let drop about third-party developers, however, landed with a bit of a thud: they were graciously allowed to create web apps. Sure, the iPhone’s WebKit-based browser let creative HTML, CSS, and JavaScript programmers create far more than dull web pages, but the apps still faced frustrating limits compared to Apple’s native apps. It took some additional months, but Apple eventually released a genuine software development kit (SDK) to allow third-party programmers to create native applications for what was then called the iPhone OS. Part of Apple’s task was also creating the App Store to distribute apps—yet another industry-transforming effort. Many existing Mac OS X developers rejoiced because the iPhone OS was derived from Mac OS X. The iPhone SDK was based on the same Xcode tools that Mac developers had been using for some time. The language of choice was Objective-C. As a happy iPhone early adopter, I eagerly awaited the iPhone SDK. Unfortunately, despite my years of being a dedicated Mac user since 1984 and a scripter since 1987 and the HyperCard days, I had never done any Mac OS X programming. I didn’t know much about C and next to nothing about Objective-C. Still, I thought perhaps my years of experience in JavaScript would be of some help. After all, at one time I even learned enough Java to write a small browser applet to demonstrate how JavaScript code in a web page can communicate with the applet. At least I knew what a compiler did. xi
  • 18. When the iPhone SDK landed on my Mac, I was simply overwhelmed. The old meta- phor of trying to sip from a firehose definitely applied. The more I read Apple’s early developer documentation, the more I felt as though I had to know a lot more than I knew just to understand the “getting started” texts. With JavaScript having been the most recent language acquisition for me (albeit back in late 1995), I looked for anything I could borrow from that experience to apply to iPhone app development. I’d see occasional glimmers, but I was basically flying blind, not knowing what I had to discard and what I could keep. The SDK was evolving during that time as well. I’d read a tutorial here and there, but I wasn’t making much headway at first. Some tools, especially Interface Builder, felt incomplete to me. Frankly, I had a couple of false starts where I walked away until a future SDK version appeared. Finally, I reached a point that was “put up or shut up.” After sticking with it and reading many of the documents many times, I was, indeed, getting tastes from the firehose. Working on iPhone development as a part-time effort over a three-month period, I managed to go from the starting line to submitting my first app to the App Store in January 2009. Since then I’ve been monitoring the developer communities on both the native app and web app sides. I’ve even sat in online courses for web app developers to see what they’re saying in the chat room. A lot of web app developers seem to look enviously to native iPhone and iPad development. I suspect many have gone through the same false starts that I did. And yet I know from my own experience that it is possible to make the transition from web app to native app developer if you know how to channel your JavaScript knowledge into what is now known as the iOS SDK environment. What You Need to Start I have written this book specifically for the web developer who is comfortable in the JavaScript language. Even if you use a bit of JavaScript to glue together apps from third- party JavaScript libraries and frameworks, you should be ready for this book. Unlike most entry-level iOS programming books, this one assumes that you have not neces- sarily worked in a compiled language before. You probably have little or no experience with C or Objective-C. But you do know what a string and an array are because you use them in your JavaScript work. I will be introducing you to the way Objective-C works by comparing and contrasting what you use in JavaScript. It’s the kind of hand- holding that I wish I had when I started learning iPhone app development. You will get more from this book if you are the adventurous type. By adventurous, I mean that you will follow the instructions throughout to try things for yourself. Along the way I will help you build an app called Workbench, where you will be able to play and learn by experimenting with little pieces of code here and there. Creating projects, editing files, and building apps is the only way to really get to know the SDK. xii | Preface
  • 19. Of course, you’ll need a Macintosh running Mac OS X version 10.6 (Snow Leopard) or later. I’ll have more details about getting set up with hardware and SDK software in Chapter 2. What’s in This Book Perhaps because my programming knowledge has been completely self-taught over the decades, this book does not follow what some might term traditional programming languagetraining.Firstofall,youalreadycometothebookwithspecializedknowledge. The goal of the book is to pick up where that knowledge leaves off and fill in the gaps with the new material. There’s no doubt about it: there is a lot of new material for you. But I have tried to establish a learning progression that will make sense and keep you interested while you learn the decidedly unglamorous—but essential—parts of iOS programming. Chapter 1 goes into detail about the differences between web app and native app pro- gramming for devices running iOS. It’s not all roses for native app development, as you’ll see, but I believe the positives outweigh the negatives. In Chapter 2, you will install the iOS SDK, inspect one of the sample apps, and run it on the iOS Simulator. Then in Chapter 3, I put you to work to create your first iPhone app—the Workbench app that you’ll use throughout the rest of the book. The steps are intended to help you get more comfortable with Xcode and learn what it’s like to work on an app in the environment. In Chapter 4, you will use the Workbench app to build your first Objective-C object and compare the process against building the same object in JavaScript. You will spend a lot of time in Xcode. And if you’ve used JavaScript frameworks for your web app development, wait until you get a peek at the frameworks you’ll be using in iOS app development. The focus of Chapter 5 is understanding how the code you write commands an iOS device to launch your app and get it ready for a user to work with. In the process, you’ll learn a great deal about how an app works. In fact, by the end of this chapter, you will add a second screen to Workbench and animatedly switch between the two. Sometimes while learning new material, you have to take your medicine. That happens in Chapter 6, where you meet three programming concepts that are foreign to what you know from JavaScript: pointers, data typing, and memory management. There will be plenty of sample code for you to try in the Workbench app to learn these new concepts. Objective-C is built atop the C language. There is still a bit of C that you should know to be more comfortable in the newer language. Chapter 7 shows you what you need to know from C. The good news is that a fair amount of it is identical to JavaScript. Hooray! And most of the esoterica isn’t needed because it’s all covered in more robust Preface | xiii
  • 20. and friendly ways in Objective-C, as covered in Chapter 8. There you’ll learn how Objective-C handles strings, arrays, and other data collections. The final chapter, Chapter 9, is also the longest. It provides a catalog of programming tasks you’re accustomed to, but implemented in the iOS SDK. Most of the jobs will be familiar to you—formatting numbers, performing date calculations, sorting arrays, working with user-entered text, having Ajax-like communications with a server, and even dragging an item around a screen. I don’t expect you to learn and remember everything described in Chapter 9, but know what’s there and how to find it when the need arises in your own iOS development. Two appendixes round out the offering. One provides tips on using the iOS SDK’s documentation to its fullest extent. The other presents a list of common Xcode compiler errors that beginners encounter and what the errors really mean. Unintelligible error messages in the early going of learning a new environment can be very frustrating and discouraging. Appendix B makes it possible to learn more quickly from newbie mistakes. Conventions Used in This Book The following typographical conventions are used in this book: Plain text Indicates menu titles, menu options, menu buttons, and keys. Italic Indicates new terms, URLs, email addresses, filenames, file extensions, and direc- tories. Constant width Indicates variables, methods, types, classes, properties, parameters, values, objects, XML tags, the contents of files, and logging output. Constant width bold Highlights new code or code of special importance in examples. Constant width italic Shows text that should be replaced with user-supplied values. This icon signifies a tip, suggestion, or general note. This icon indicates a warning or caution. xiv | Preface
  • 21. Using Code Examples This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning the iOS 4 SDK for JavaScript Programmers by Danny Goodman (O’Reilly). Copyright 2011 Danny Goodman, 9781449388454.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at [email protected]. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at: http://www.oreilly.com/catalog/9781449388454 To comment or ask technical questions about this book, send email to: [email protected] For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our website at: http://www.oreilly.com Preface | xv
  • 22. Safari® Books Online Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly. Withasubscription,youcanreadanypageandwatchanyvideofromourlibraryonline. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, down- load chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features. O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other pub- lishers, sign up for free at http://my.safaribooksonline.com. Acknowledgments Having published over 45 books since the early 1980s, I have witnessed many changes across the computer-book universe. But one beacon of quality has always burned brightly: O’Reilly. The opportunity to publish a title through O’Reilly inspires an author to produce a work commensurate with an impeccable publishing record. It was a comfort to have super-knowledgeable editors Brian Jepson and Andy Oram chal- lenging me to compose a better book at every step. Technical reviewers Alasdair Allan and Zachary Kessin responded above and beyond the call of duty to make sure my facts were factual and the reader’s best interests were being served. xvi | Preface
  • 23. CHAPTER 1 Why Go Native? Those who frequently develop mobile web applications with HTML, CSS, JavaScript, and related technologies tend to find a way to reuse those comfortable tools for every app challenge. The iOS (formerly iPhone OS) platform has attracted much attention in the web developer community, and Apple continues to evangelize web app devel- opment for the platform. At the same time, there’s evidence of a desire among developers to adapt their web technologies to replicate the look and feel of native iPhone and iPad apps, whose look and feel users know from the built-in apps and other apps downloaded from the App Store. Perhaps you’ve used third-party libraries, such as iUi or jQTouch, to deploy your content and application ideas so that they look and behave like native iOS apps. Despite advances in web technologies—especially the HTML5 and WebKit extensions to CSS and Document Object Model (DOM)—an iPhone or iPad web app lacks access to several key facilities built into iOS. You must also deal with the Mobile Safari browser address bar, especially if your users aren’t experienced enough to generate a home screen icon for your app. Additionally, even though both your iPhone-specific styles and scripts target a single OS platform, you still may encounter compatibility issues with earlier versions of Mobile Safari running on iPhone and iPod touch units in the field that haven’t been updated to the latest OS versions. For example, I saw from my server logs that nine months after the release of iPhone OS 3.0, some users of my native iPhone apps continued to use iPhone OS 2.2, especially with iPod touch devices (most of whose users once had to pay for major OS upgrades). In other words, the choice to reach iPhone and iPad users through web applications, which were supposed to simplify development, introduces its own set of complications. Maybe it’s time to make the leap and start developing native iOS apps. This chapter highlights iOS features you can use if you choose to develop native apps—features that are not available to web-only apps. Even if your app designs don’t require a lot of native OS support, a native app still has advantages over web apps. To provide a fair and balanced picture, I’ll also discuss what you lose by using a native app over a web app. 1
  • 24. Using an App Offline It is hard to argue with the fact that iOS devices are intended to be used in a connected world. WiFi is built into all devices by default; iPhones and iPads (and likely future devices) equipped with 3G also have cellular data connections that free users from lurking around WiFi hotspots. Unfortunately, users may be out of WiFi range, have no cellular connection, be running dangerously low on battery power, or be secured inside a jet-powered flying metal tube whose attendants prohibit radio contact with the ground. When an iOS device cannot access the Internet, a traditional web app—which resides entirely on your web server—is not accessible. Although it is possible to code a browser-based web app to be copied and stored on a device, the mechanism isn’t foolproof. A native app, however, is at least launchable even when the device has no connection to the Internet. Exactly how usable the app is while offline depends on the nature of the app, of course, but it’s clear from the apps that Apple supplies on every device that an iOS device does not completely die if Internet connectivity is missing. You can still listen to music, watch previously downloaded videos, look up your contacts, and tap out notes; with an iPhone and iPod touch, you can still be awoken by an alarm or calculate a total; and with any camera-equipped device, you can take pictures. Appli- cations you download from the App Store let you do tons more things, such as play games, read gorgeous-looking downloaded books, edit photos, figure out restaurant bill tips, look up a dictionary definition, or identify a bird in the nearest tree—all with- out the need for a constant Internet connection. Many native apps also connect with the Internet for some functions. Games commonly upload scores so you can see how well you perform against other users around the world. Many apps also rely on the Internet for up-to-date information, such as email apps, news readers, weather apps, Twitter and Facebook clients, and many more. For designers of many of these types of apps, the challenge is to create an app that can perform its basic functions offline, even if it means the user needs to download some current content before cutting the wireless cord. Once disconnected from the cloud (perhaps even while flying above the clouds), the user can relaunch the app and still access fairly recent content. Unfortunately, you cannot rely on Mobile Safari to preserve a downloaded web page’s content for long. Even if the user manages to keep the Safari window open, restoring it for use sometimes causes the page to attempt to reload itself from the server. No server? No content, even though it may be in a cache someplace on the device. Some web apps have successfully been converted to bookmarklets. A bookmarklet is a browser bookmark that contains a javascript: or data: URL whose code generates the HTML, CSS, image data, and JavaScript code for a web page when chosen from the browser’s bookmarks list. It’s true that this method allows a web app to be stored entirely on the user’s device, but a web page generated in this fashion has some 2 | Chapter 1: Why Go Native?
  • 25. additional limitations over regular web pages. For example, a bookmarklet app cannot use browser cookies because of security restrictions in the browser. Mobile Safari does support the HTML5 offline application cache. This mechanism allows web app publishers to code their pages (and configure their web servers) in a way that allows the browser to store a copy of a web page and additional resources (e.g., images) on the device. Developers deploying this technique have a variety of limits to attend to, such as a maximum of 25 KB for any resource file, including any images. Of greater concern, however, is that if the user reboots the device (completely powering down the unit), all data in this offline cache can be lost. Native apps, however, survive such system reboots every time. There is a risk that when you have been designing Internet-based content and software for a long time, you tend to take Internet connectivity for granted—after all, you have always-on broadband at home or work. Additionally, all the buzz about cloud com- puting makes it sound as though every computer user on the planet has ubiquitous and nearly free access to an Internet that is as reliable as the sun rising tomorrow morning. That is not always the case for all users. More Access to the Hardware Itdoesn’ttakelongtolearnthatwebpagesdevelopedforgeneral-purposewebbrowsers are encumbered with many restrictions. For example, a web page does not have free rein over the host computer’s filesystem, making it impossible for well-meaning scripts to read or write files on the hard disk (except for closely monitored dedicated files for items such as cookies and HTML5 data storage). JavaScript is granted very limited access to even the host browser’s environment or settings. Despite the possible con- venience afforded by automatically adding the current web page to a user’s bookmarks list, such access is out of bounds for web pages. All of these restrictions, of course, are imposed for the sake of security and privacy. Left unfettered, a script on a malicious hacker’s website could wreak havoc on every browser that lands at the site. Not many users would like unknown computers reading their recent browser histories or replacing system files with ones that could cause banking website visits to be redirected to lookalike phony sites that capture usernames and passwords. Cyber crooks are constantly on the prowl for vulnerabilities in popular browsers that they can exploit without the user’s knowledge—the so-called drive-by attacks that have plagued various browsers through the years. An application designed to run natively on popular desktop computer operating sys- tems, on the other hand, typically has exceptionally broad freedom to rummage around the computer at will. On some operating systems that are set up for user accounts, the user must grant specific permission to the program’s installer. Such permission is taken to mean that the user trusts the installer and the program(s) it installs to do no harm. Developers who publish software with a goal of building a software business avoid More Access to the Hardware | 3
  • 26. doing bad things to customers’ computers even though users essentially hand over the key to the system. On the other hand, if a program has a hidden agenda (e.g., loading spyware onto every user’s computer), the nefarious activity will likely be discovered sooner or later. News of the offenses will carry quickly across the Internet and the company’s reputation will be ruined. Apple engineers have thus far greatly restricted the hardware features available to web apps running in Mobile Safari. Despite some cool hardware, such as the digital compass in the iPhone 3GS, web apps simply have no access to most of the neat stuff. About the only hardware-based features that a web app can count on are: • Accelerometer orientation changes (e.g., portrait or landscape) • Gyroscope motion (iOS 4.2 or later) • Multitouch events (e.g., two-finger pinching or stretching) • Location services (as many as are supported by the device) Native apps, however, have substantially more access to the hardware—although not necessarily every piece that developers might like. For example, apps built for devices containing cameras can capture images (and video, where available) to facilitate image editing tasks. Devices equipped with a digital compass expose the current heading of the device. Sound captured by the device’s built-in (or plugged-in) microphone can be recorded and further processed by code inside a native app. An app can read informa- tion about the battery state and an iPhone’s proximity detector (which knows when a user has the handset near her face). Native apps can also read from and write to files of their own construction (albeit within some security-driven confines of the directory structure reserved for the app). Although Apple has begun to expose limited parts of the hardware to web apps (essentially creating objects, properties, and methods that extend the DOM), such exposure lags well behind the range of hardware features waiting to be used by native app developers. I expect more hardware access to come in future iOS versions, but web app access will likely stay several steps behind native app capabilities. More Access to the Software On the software side of the iOS, native app development offers a wide range of features that web app developers don’t typically have available. For example, here is a list of software features introduced with iPhone OS 3.0 that are available only to native apps: • iPod library access to read library contents and play tracks • Displaying interactive embedded Google Maps with many of the same capabilities and identical performance to that of the Maps app • Peer-to-peer communications for multiplayer game play • Precise control over how cut/copy/paste works in an app 4 | Chapter 1: Why Go Native?
  • 27. • Powerful structured data mechanisms ideally suited to displaying lists (the Core Data framework) • Precise control over audio recording details (sampling rates, audio formats, etc.) • Push notifications to signal users about important events that launch your app • Creating and sending email messages from within the app • Reading and selecting information from the Contacts app • Very powerful OpenGL ES 2.0 3-D graphics composition platform • In-app purchases to encourage users to add paid features or extend subscriptions If that list doesn’t send your imagination into overdrive, perhaps several new native app features of iOS 4 will: • Playing audible media while the app is suspended in the multitasking environment • Receiving system notifications of changing between active and suspended mode • Posting notifications to users at predetermined times, even if the app is suspended • Integrating with Calendar app data • Displaying revenue-generating advertisements from Apple’s iAd service It’s not uncommon for native app developers to apply several of these advanced software features (along with hardware features mentioned in the previous section) to augment their apps. For example, one of my own native apps, iFeltThat Earthquake, uses the in-app email feature to make it easy for users to contact me with questions and suggestions about the app. The app also lets users select an entry from their Contacts list to create a geographical center point around which recent earthquake activity is shown (the app uses geocoding to convert a contact’s street address to map coordinates). All of this native software goodness still allows developers to fold useful web content into a native application. iOS supplies a mechanism for displaying live web content within a native app. The “viewer” used for such web content has all the HTML, CSS, and JavaScript features of Mobile Safari (and its WebKit engine), but without the chrome of the Safari app. You simply define a rectangular viewing region on the screen and supply a URL to the web viewer. In iFeltThat Earthquake, for example, I keep users informed about news and user tips via an HTML-authored page made available from a web server. Each time the app launches, it looks to see if the news web page has been modified since the last visit; if so, it downloads the page, stores a copy on the device, and signals the user that a news flash is available for reading. I chose to compose the news material in HTML for a couple of reasons. First, as a veteran HTML handcoder, I am, of course, comfortable generating content in that format. It allows for quick composition and easy testing of the page from a local server using Mobile Safari on an iPhone-compatible device. It also means I am free to change the styles (CSS) of the news page without having to update the entire app. The second reason for choosing HTML is that I can easily provide links to other HTML content, More Access to the Software | 5
  • 28. whether composed by me or served from a different external source. Because the news page is shown within a web viewer inside the app, links operate as they do in any browser, replacing the current page with the destination of the link. My in-app web viewer provides just a minimum of browser controls for reloading, stopping a load, and back and forward navigation. In many ways, web development skills are powerful adjuncts to native iOS app devel- opment. Being comfortable in both environments means you can call on the right deployment tool for various parts of a native app. Hardcore Objective-C and Cocoa developers might be wary or unaware of the web powers that you have in your hip pocket. Once you master native app development, you’ll have a distinct advantage over your Objective-C-only colleagues. What You Lose By and large, the full iOS SDK feature set offers your app designs far more flexibility and the ability to recreate the full range of user interface features you see on Apple’s own apps and apps developed by third parties. But there are costs—in monetary and toil currencies—to obtain those native app powers. Except for apps designed for in-house corporate use, native apps that run on nonmodified devices—i.e., iPhones and iPads that have not been jailbroken (hacked to allow unapproved third-party apps)—must be distributed via the iTunes App Store. This is both a blessing and, for some, a curse for several reasons. About Jailbreaking When the first-generation iPhone landed in developers’ hands in 2007, quite a few programmers were put off by the lack of a publicly available development environment for applications. Apple granted itself the power to build native apps included with the phone, but the developer community was shunted to the web app world—with a Mobile Safari version boasting far fewer app-friendly features than today’s HTML5- empowered model. Some adventurous programmers, however, found ways to gain access to the same interior programming functionality that Apple’s engineers had and opened up native programming to third parties. Having pierced through Apple’s re- strictions, they called the technique jailbreaking. To run one of these independent apps, an iPhone user had to “jailbreak” the device using a software-run process that grew easier and easier over time as jailbreaking tools improved. Several months after the initial iPhone debut—and perhaps pushed by the encroaching jailbreak programming efforts—Apple released the iPhone SDK to allow third parties to write native apps, but only with publicly documented routines. That restriction still rankles some developers, so jailbreaking is still alive today, even as Apple continually opens more internal routines to all developers. Jailbroken devices reportedly account for as much as 10% of the world’s iPhone and iPad population (but a higher percentage ofactivetechbloggers,whomakejailbreakingseemmoreprevalentthanitis).Although 6 | Chapter 1: Why Go Native?
  • 29. jailbroken devices can still download apps from Apple’s App Store, a separate store, called Cydia Store, offers apps designed for jailbroken iPhones and iPads. Some programmers believe it is almost an obligation to jailbreak their devices, lest they appear captive to the will of Steve Jobs. I personally prefer not to jailbreak my devices, for practical, rather than ideological, reasons: I want to know that when I test my App Store apps, the devices are working like the ones owned by 90% or more of my potential customer base. The ultimate choice, however, is yours. Distribution On the one hand, since the App Store is a single point of distribution, all users of unhacked iPhone, iPod touch, and iPad devices go to the App Store in search of apps that will help them scratch an itch. While you may have to choose your app’s descrip- tion keywords carefully to help potential users search for your product, at least you don’t have to play search engine optimization games to get your app high in search engine results. On the other hand, the App Store becomes the one-and-only gatekeeper between your app and the consuming public. You must submit your finished app to the App Store for approval before it appears in the store. Approval times can vary widely, often with- out explanation. Sometimes it’s a matter of only a couple of days; other times it can take weeks. The same is true for updates to existing apps. If you need to issue an update to fix a bug, the approval time can be just as long—and, inexplicably, sometimes longer—to get that maintenance release out to the world. You can apply for an emer- gency update to help hasten the approval, but if you abuse that privilege, you risk upsetting the gatekeepers. App Updates Speaking of updates, the web app scenario is far superior to the App Store native app. You instantly deploy an update to the server that hosts the web app whenever you want, as often as you want. This encourages web app developers to issue frequent incremental updates rather than storing up fixes to submit to the App Store in less-frequent batches. If your app updates are more content-oriented, you can still pass along those updates to a native app in a couple of ways. I described earlier how I use HTML to supply my native apps with news updates. Similarly, updated material can be supplied in other formats(e.g.,propertylistXMLfiles),whichanativeappcanreadwheneveritlaunches. Users can save newly acquired material to the device so that it is available to the app even if the device is not connected to the Internet the next time the app launches. Implementing this approach to updating an app takes a bit of advance planning, so it is well worth exploring the possibility early in the design phases of any iOS app. What You Lose | 7
  • 30. Apple iOS Developer Program A prerequisite to submitting a native app to the App Store is an annual paid membership to the iOS (formerly iPhone) Developer Program. The current fee is $99.00 per year. Membership lets you obtain the necessary digital certificates that permit developers to load native apps onto test devices and to upload finished apps to the App Store for approval. You also have access to beta versions of the next version of iOS SDK and iOS software (all under nondisclosure agreements, so you can’t blab about them). In addition to paying the developer program fee, you must also complete a distribution contract with Apple. For paid applications, the contract process also requires that you establish banking relations with Apple. As with app approvals, the time required to complete the contract varies depending how busy Apple is. It’s not something to leave to the last minute, because it can take several weeks to complete, even longer for developers outside of the United States. Once you pay for the iOS Developer Program, you should begin the contract process, even as you work on your first native app. Content As the gatekeeper to “shelf space” on the App Store, Apple’s approval process also imposes restrictions on the content of native apps. Your developer agreements spell out the fundamental guidelines, but Apple inspects each app for compliance on a case- by-case basis. Such is not the case for web apps. You can serve up whatever you want (within the confines of your own local laws, of course) because the web app is hosted on your server and the device’s owner can freely decide to visit your server or skip it. If you are already aware that web apps—indeed any content designed to be played through the Mobile Safari browser—cannot avail themselves of Flash or Java, you should also be aware that native apps don’t get you any further with respect to those two software platforms. As of this writing, iOS does not natively support either runtime environment. Authoring Platform Choices You can write HTML, CSS, and JavaScript code with a text editor on any operating system platform of virtually any generation. Plain text editing doesn’t even require a graphical user interface, which is why you can find plenty of Unix programmers com- posing web code in command-line interface editors, such as Emacs and vi (or variants thereof). The key to this flexibility is that conversion to machine code occurs in the web browser. Such is not the case for writing native apps. 8 | Chapter 1: Why Go Native?
  • 31. Developing native iOS apps requires Apple’s integrated development environment (IDE) called Xcode (pronounced EKS-code). Even though Windows users can sync their iOS devices to their PCs via iTunes for Windows, the Xcode IDE is available only for Macintosh computers. Taking the Plunge Beginning with the next chapter, you will see the changes to the development process and programming environment that you will have to adopt to develop native apps. Some of the changes are radical, so if you jump into the programming environment cold, the transition will seem overwhelming. But, just as you learned the intricacies of CSS, JavaScript, and the DOM, the same will happen with iOS SDK development with practice and experience: throughout this book, you’ll learn new concepts that build upon one another. My purpose here is to help you embrace that transition by putting new items in the context of your existing knowledge. Let’s get started. Taking the Plunge | 9
  • 33. CHAPTER 2 Welcome to the iOS SDK Even in these days of powerful high-level web authoring tools, it’s still quite common for JavaScript programmers to compose or modify code with nothing more sophisti- cated than a text editor. Perhaps you use that text editor to work on .html, .css, and .js files that users access directly; or you use that text editor to write server code (in Python, Perl, Ruby on Rails, or one of several other languages), which in turn assembles HTML code served up to requesting browsers. With the browser operating as a code interpreter (even if it performs some fast precompiling behind the scenes), the write-test-debug cycle is pretty fast: make a code change and reload the browser to test the results. Egregious errors, such as JavaScript syntax errors, signal themselves while the page loads; more subtle errors, such as referencing an object that hasn’t yet been created, fill the error console when the code runs. When you switch to native app development, this comfy authoring environment and cycle go out the window. Luckily, it’s replaced with an integrated and visually oriented environment that—once you learn its ways—reflects a lot of the best in modern pro- gramming environments. This is the native iOS app SDK, whose nucleus is Xcode. Among other things, Xcode helps you visualize and manage the potentially large num- ber of files associated with each app in development. Additionally, the tools delivered with Xcode are highly integrated. For example, you will write some code that responds to a user tapping a button in an iPhone app: the tool you use to create the user interface is aware of the code you’ve written and helps you connect the button in the user interface to that code. The user interface building tool is instantly aware of changes you make to the code, even though the tools are two separate programs in the Dock. Hardware and OS Requirements As mentioned in Chapter 1, you need an Intel-based Macintosh running Mac OS X version 10.6 (Snow Leopard) or later to use the Xcode IDE. As Apple releases new versions of the iOS SDK and Mac OS X, requirements may change. 11
  • 34. You don’t need a brand-spanking-new Intel-based Mac to develop iOS apps. There are plenty of used Intel Macs for sale on eBay and elsewhere. For the tower- or iMac-averse, laptop styles—MacBooks and MacBook Pros—are well suited for iOS development, except perhaps for a possibly small screen. If you can afford a large external LCD mon- itor, you will have an easier time managing your project windows. And maxing out a laptop’s RAM slots will also contribute to good performance of Xcode. Installing the SDK To begin your exploration of iPhone development, start by signing up to become a Registered iOS Developer at: http://developer.apple.com/programs/start/standard/ Registration requires that you have an Apple ID. If you have an iTunes account or if you have purchased from the Apple Online Store, you already have an Apple ID. Otherwise, you can sign up for one online while you register as an iOS Developer. The free version of the iOS Developer program lets you download the full SDK from the opening page of the iOS section of the Apple Developer website. Be sure to confirm you have the minimum Mac OS X version required for the current SDK you’re about to download. The iOS SDK is huge—well over three gigabytes. Be patient with the download. It arrives as a compressed disk image, a file with a .dmg extension that expands into a mounted disk volume. If the completely downloaded file does not automatically ex- pand, double-click the file to mount the disk image on your Desktop (some browsers will do this for you automatically after the download is complete). The disk image will open itself to reveal installer notes and a package file containing the SDK (Figure 2-1). Double-click the .mpkg package file to run the SDK installer. I recommend following the default choices presented at each step of the installation process. Allow the SDK to be installed in a new Developer directory on your startup disk. If you have iTunes running, you will be prompted to quit the app before the installation will complete. After installation has finished, you can drag the disk image and compressed image file to the Trash. About iOS Developer Programs The free version of the iOS Developer program allows you to use the SDK to run native apps you create only on the iOS Simulator program (one of the SDK tools), which runs only on the Mac. To upload a native app to an actual device for testing (or your own use) and to submit an app for distribution through the App Store, you must sign up for the $99.00 (per year) iOS Developer Program (or the $299.00 Enterprise Program for companies planning to write apps only for employee use). This paid developer program also grants you access to an Apple-hosted online forum where you can ask for coding 12 | Chapter 2: Welcome to the iOS SDK
  • 35. help (or read how others may have already solved your problem). Additionally, when Apple releases beta versions of the next iOS version and associated SDK, paid members can download those pieces for development and testing purposes. For example, on the day that iPhone OS 4.0 was announced in April 2010, members of the developer pro- gram could download a beta version of Xcode to write apps and a beta version of the OS to install on devices to see how the new features worked. You will not be able to submit apps to the Store that you have built from a beta version of the SDK. Therefore, if you have one or more apps on the App Store, you should always keep a current version of the SDK on hand for building updates to existing apps. Historically, it has been possible to install both the current and beta SDK versions on a single Mac,ifdesired(youstillneedtoinstallthebetaSDKinaseparatefolder). You can go pretty far toward developing your first iOS app without investing a dime in Apple developer programs. It’s a free way to discover if programming for iOS in the Objective-C language is right for you. But don’t wait too long to decide to sign up for the paid program. Once you sign up for that program, but before any app you create can appear on the App Store, you must still go through a contract and banking cre- dentials process with Apple, all of which is handled online. Each developer has had a different experience with completing the contract and banking agreements. For some, the process takes only a few days; for others, it can take months. What you want to avoid is waiting to begin the contract process until you submit your first app to the App Store. In my case, the first app I submitted in early 2009 was approved in three days; the contract, however, took almost one month, during which time my approved app sat in limbo. Figure 2-1. Contents of the iOS SDK disk image About iOS Developer Programs | 13
  • 36. Inside the SDK TheDeveloperdirectorycontainingtheiOSSDKiswellovereightgigabytesofgoodness waiting for you to explore. You will spend most of your time in four applications, three of which are highlighted in Figure 2-2. Figure 2-2. Three primary applications of the iOS SDK (version 3.2.5 shown) The four primary tools are: Xcode This is the integrated development environment where you will write your code, keep track of external files (images and others), and build your app for testing and eventual submission to the App Store. 14 | Chapter 2: Welcome to the iOS SDK
  • 37. Interface Builder You are not required to design your user interfaces using this graphically oriented design tool, but if your app utilizes standard iPhone or iPad user interface elements, it can significantly reduce the amount of code you write. Instruments After your app reaches a usable form, you will use Instruments to observe how well it uses memory and system resources. iOS Simulator Although the iOS Simulator app is buried elsewhere within the Developer directory hierarchy, you will use it often during all development phases for both iPhone and iPad testing (the tool contains simulators for both platforms). The simulator launches from your Xcode project windows. Each time you go to work on your app, you begin by launching Xcode. You can launch all of the other supporting apps directly from within Xcode. For example, when you want to see how well the current implementation runs on the iOS Simulator, you will instruct Xcode to build the app and run it on the simulator. If the simulator is not yet running, Xcode will launch it, install the app, and launch the app on the simulator. Viewing Developer Documentation The first time you launch Xcode, you will see a Welcome to Xcode window with a variety of choices, as well as a list of previously opened projects (probably empty for you). Click Cancel for now. Instead, open the Help menu and choose Developer Doc- umentation, as shown in Figure 2-3. You will be referring to documentation a lot, and this menu (or keyboard equivalent) is a quick way to open the documentation window before you open a project. Figure 2-3. Accessing developer documentation in Xcode Viewing Developer Documentation | 15
  • 38. The best place to begin in the developer docs is the home page for the latest iOS SDK you are using. Figure 2-4 shows where the main navigation menu is located and what the home page looks like. The Xcode documentation system can display multiple sets of documentation for different iOS versions and Mac OS X development (selectable in Xcode preferences). Figure 2-4 shows only the iOS 4.2 doc set installed. Figure 2-4. iOS 4.2 SDK documentation home page After you’ve finished this book, the Getting Started section (upper right box in Fig- ure 2-4) is the place to go next. You’ll have enough links to keep you busy for quite a while. While we’re on the subject of the developer docs, let me also show you how you will interact with the iOS Reference Library while you compose your code. In particular, you will frequently need to look up how various objects work. Simply enter a term into the Search box in the upper-right corner. For example, by the time you are finished with this book, you will know that Objective-C arrays are instances of the NSArray object. To read the details of the NSArray object, simply enter the object name into the case-insensitive Search box (Figure 2-5). The left column contains a list of documents and items within those documents that match the search string. If you have multiple documentation sets for different iOS 16 | Chapter 2: Welcome to the iOS SDK
  • 39. versions installed in your copy of Xcode, the search results will show separate entries for each version—all named the same. This can be confusing at first glance, but you can hold the pointer over any item in the returned list to see the doc set to which that item belongs, as shown in Figure 2-6, which shows what the top of the search results looks like when two iOS doc sets are installed. Figure 2-6. Hover over an item to reveal its doc set As shown in the middle and right columns of results of the NSArray search (Fig- ure 2-5), reference documents frequently include links to various programming guides and sample code projects that come with the SDK. Each programming guide is a gold- mine of information, especially for programmers who are new to the guide’s subject matter. Read those guides thoroughly—and perhaps multiple times—to learn the gos- pel according to Apple. Very often, these documents assume you have a working Figure 2-5. Searching for details on the NSArray object Viewing Developer Documentation | 17
  • 40. knowledge of Objective-C and other aspects of the iOS SDK, most of which you will be exposed to throughout this book. Loading Code Samples A comparatively recent innovation in the iOS SDK is a simplified way to open a copy of a code sample that you can play with at will without worrying about messing up the original. Figure 2-7 shows the result of clicking on a link to a code sample—called TheElements—shown at the bottom of the right pane in Figure 2-5. For sample code, the Table of Contents panel lists the files associated with the sample project. Direct your attention to the button on the righthand panel. Figure 2-7. Landing page for the TheElements code sample Use the following steps to load the sample into Xcode: 1. Click the Open Project in Xcode button. 2. Select the folder where the installer will create the project’s folder (i.e., a folder named TheElements will be created for you, so choose where you want that folder to go). 18 | Chapter 2: Welcome to the iOS SDK
  • 41. 3. Click Choose. The installer script copies all necessary files into a folder named TheElements and immediately launches the project file, named TheElements.xcodeproj. A .xcodeproj file is the master hub for everything associated with the app and is the file you open when- ever you want to work on an app. Figure 2-8 shows the Xcode project window for TheElements sample project. Figure 2-8. TheElements project window in Xcode While the project window may look intimidating at first, you won’t be dealing with most of what you see here on a daily basis. Your focus will primarily be on items listed in the lefthand Groups & Files section and mostly on items in the top group (above the Targets group). This is where your source code files, images, and other contributing files for the app go. The column view of the project contents shown in the top right-hand pane is another view you won’t be looking at much, if at all. Instead, drag the divider between the two right-hand panes upward all the way to give yourself a larger source code editor view (see Figure 2-9). Because no file is selected yet, the editor pane reads “No Editor.” You can now open the various group folders to expose individual source code files. When you click any source file, the appropriate editor appears in the editor pane, as shown in Figure 2-10. Loading Code Samples | 19
  • 42. Figure 2-10. Select a source code file to view its contents in the editor Figure 2-9. Drag the bottom divider upward to reveal more of the editor 20 | Chapter 2: Welcome to the iOS SDK
  • 43. Sample source code files supplied by Apple almost always begin with a lengthy com- ment (in green text according to the default text-color scheme). After a brief description of the file comes a lot of legal and licensing text. The actual code comes afterward. Feel free to scroll down the editor to get a taste of what iOS SDK app source code in Objective-C looks like. Coding Styles in SDK Samples Different Apple engineers write code samples supplied with the SDK. You will therefore find a variety of styles in the way projects are composed. The lack of uniformity can be confusing to newcomers who desperately want to adopt a solid coding style. At best, you should look to the samples as just that: mixed samples rather than specific instructions on how to structure projects, name variables and methods, or even how to divide code into separate files. Additionally, most samples aim to demonstrate a specific concept rather than define an all-around best practice example. Pieces of some samples distant from the primary subject matter may even be less than optimal. There- fore, as you learn more about Objective-C and the SDK, don’t be afraid to employ your own structure and styles that are comfortable for you. Setting the Project’s Base SDK You probably noticed that the Overview menu at the upper-left corner of the project window says “Base SDK Missing.” Before you can compile an app and run it, you need to set the SDK version Xcode should use for compilation and deployment. Because TheElements project was created when SDK version 3.0 was still available and modified to build for iOS 4.0, Xcode in the iOS 4.2 SDK doesn’t recognize the setting as being valid. It’s time to bring the setting up to date by adjusting what is known as the Target—a collection of specs Xcode uses to build an application around the source code of the project. Open the target’s settings by choosing Project→Edit Active Target “TheElements”. You will see the Target Info window. In the first group of settings is the Base SDK, which confirms that the originally specified SDK 4.0 is not available. Click in the right column to reveal your possible Base SDK choices, as shown in Figure 2-11. Choose Latest iOS. This setting will allow the project to work in future SDK versions without further adjustment. Close the Target Info window. The Overview menu should now indicate “4.2|Debug| TheElements” or similar indications. If the Overview menu doesn’t change, close and reopen the project. In the next chapter, you will work with an additional setting that will let your app work with iPhone devices running OS versions as early as 3.0—even though the Base SDK is still set to 4.2. Setting the Project’s Base SDK | 21
  • 44. Trying the iOS Simulator To make sure your Xcode installation and sample code are working properly, you should try running the sample in the iOS Simulator. The first step is to direct Xcode to build the app for the simulator rather than for a device. You don’t have the necessary certificate to load this app onto an actual device, so the simulator will do for now. Near the upper-left corner, click the Overview drop-down menu. Choose Simulator, as shown in Figure 2-12, if it is not already chosen. Then, choose TheElements - iPhone Simulator 4.2 from the Active Executable group. Next, click the Build and Run button in the center of the top toolbar You will see the stages of the build process displayed in the lower-left corner of the Xcode project window. After a few moments, the iOS Simulator will launch (it’s a separate application from Xcode), and the TheElements app will automatically launch, as shown in Figure 2-13. Figure 2-11. Setting the project to use the latest iOS version as the Base SDK 22 | Chapter 2: Welcome to the iOS SDK
  • 45. Figure 2-13. TheElements app running in iOS Simulator Figure 2-12. Instruct Xcode to build for the simulator running iOS 4.2 Trying the iOS Simulator | 23
  • 46. Use the mouse as your finger to scroll through the list and click on buttons. Although there aren’t any images to zoom in this app, if you want to use a two-finger pinch or stretch gesture, hold down the Option key while clicking and dragging inside the sim- ulator’s active app area (you’ll see grey dots representing finger touch spots). When you quit the app on the simulator (by clicking the Home button at the bottom center), you will see an icon for the app on the iPhone home screen. The icon is one of the image files that came with the collection of files for the project. Coming Up... At this stage of your exposure to Xcode, don’t bother trying to figure out the files and structure of the sample TheElements app—it has a lot of moving parts that probably won’t make much sense yet. By the time you reach Chapter 8, however, you’ll be ready for a more detailed walk-through of this project’s component files. In the meantime, there is plenty of language material to cover. But before we get to the new language stuff, we have one more stop to make: using Xcode to create a test workbench app in which you’ll be able to study how the Objective-C language and iOS features covered in later chapters work. 24 | Chapter 2: Welcome to the iOS SDK
  • 47. CHAPTER 3 Creating a Test Workbench If there is one comfortable technique to which we HTML, CSS, and JavaScript devel- opers have grown accustomed, it is writing some tiny code samples to test expression evaluations and execution logic. You very likely have at least one test.html file some- where on your hard drive. In one of my JavaScript books, I include code for a page called The Evaluator, which allows readers (and, more importantly, me) to see values ofsingle-lineexpressionsandobtainpropertydumpsofobjects(listsofpropertynames, values, and value types for any JavaScript or DOM object in the page). It’s convenient to test code snippets initially in an environment that is isolated from your major work in progress. First, you don’t want other code to influence your ex- periment(think“scientificmethod”).Second,youdon’twantyourexperimentstomess up your existing working code. The Workbench app you will build in this chapter will provide you with a running iPhone environment (initially on the iPhone Simulator) in which you can easily test expressions, logic, and the like. Use it as a learning lab while you work through the remaining chapters of this book. Figure 3-1 shows the finished app. True, it’s nothing more than an iPhone screen with a button on it. You will set up this app so that you can test your code in the iPhone OS runtime environment by clicking that button. Results will appear in a separate window of Xcode, called the Console (more about that later). The purpose of the Workbench app is to provide a clean environment into which you can insert your little Objective-C experiments and other learning explorations, which all get triggered when you click that button. In the process of building Workbench, you will be simply following my instructions. I don’t expect you to understand everything that is going on, but I will explain many concepts to you as we go. For example, you’ll begin to appreciate the importance of choosing good names for projects in “Naming and Saving the New Project” on page 29. Later you will get to play with Interface Builder to design the layout. If you don’t fully grasp why something is the way it is, don’t worry—future chapters will cover most of these concepts in more depth, while your future introduc- tions to iOS SDK programming will cover the rest. 25
  • 48. Creating the Project in Xcode Every iOS app you generate with Xcode is managed within a container known as a project. The project file (with a file extension of .xcodeproj) knows all of your preference settings for the particular app, maintains lists of source code and other external files associated with the project, and tracks many more pieces that most app developers don’t ever touch. Each time you come back to an app you’ve already begun, you will open its project file to get back to work. For the Workbench app, begin by creating a new project. Do so from the File menu in Xcode, as shown in Figure 3-2. Selecting a Project Type The New Project menu item presents a dialog box of choices (Figure 3-3). Because Xcode is used for both iOS and Mac OS X development, you will see options for both environments (even though you downloaded Xcode with the iOS SDK from the Apple developer site, it includes the development tools for Mac OS X as well). You obviously want to focus on the iOS section, and pay attention to the options for creating apps within that section. Figure 3-1. The Workbench app 26 | Chapter 3: Creating a Test Workbench
  • 49. The type of application you choose at this juncture determines the content of the pre- written files Xcode generates for a brand new project. Apple’s Developer Tools group has gone to great pains to supply as much template code as possible to help you start your way into an app. In fact, each project template is finished enough to the point that you can create an “empty” project, build it, and install it on the simulator. It won’t do anything, but the fundamentals of an actual running iPhone or iPad app are supplied for you in the new project template. Knowing how to select the right template type comes with more experience than you have at this point, so take my word for it that a view-based application is the one you want for Workbench. Although other types would also work, it will ultimately be helpful for your experiments to have the view-based infrastructure in place. Select the View-based Application icon in the New Project window, and click Choose. Device-Specific or Universal App? When you select View-based Application in the New Project window, the Product menu allows you to produce the fundamental code for either an iPhone- or iPad- specific app. An iPhone-specific app will run on an iPad in a small display area (which the user can upscale to a full-screen view that is usually not very pretty), but an iPad- specific app cannot run on an iPhone. Xcode provides a starting point for a single Figure 3-2. Create a new project menu choice Creating the Project in Xcode | 27
  • 50. “universal” app that contains code for iPhone- and iPad-specific areas in one final app file that you can upload to the App Store. You can see that choice in the New Project window by clicking on Window-based Application and viewing the Product menu. Universal apps tend to have identical functionality for both versions, with its device- specific code providing tweaks that reflect the differences between the platforms in user interface design and screen sizes. An advantage to this approach is that you can use a single set of underlying code to handle data, network communications, and so on for both device families. The App Store, however, also has many examples of completely separate versions of an app, in which the iPad version offers additional features suited to the larger screen. Although it might require more work on your part to keep code shared between the two versions of the app in sync with each other as you release upgrades, it’s not uncommon to find enhanced iPad versions of an app commanding a higher price on the App Store. The choice between a Universal app and separate versions for iPhone and iPad is one of those factors that you should keep in the back of your mind as you begin planning your real apps. In the meantime, the fundamentals you’ll be learning in your early days will apply equally to whichever product platform(s) you eventually choose. Figure 3-3. Project choices 28 | Chapter 3: Creating a Test Workbench
  • 51. Naming and Saving the New Project Next you will be presented with a Save file dialog box. This is where you will specify the location for the project folder and the name of the app. These are two separate points that should be given a bit of thought. Be aware that Xcode will create a folder for the project (using the name you will assign in a moment). In other words, the folder location you choose in the New Project file dialog box should be a kind of master folder into which you will place each of your iOS SDK project folders (one project folder per app). By default, Xcode suggests placing your apps in the user Documents directory. I prefer to keep all my projects for a par- ticular minimum iOS version grouped together on my hard disk. Use an organization scheme that makes the most sense for you. Avoid the temptation to save your projects inside the Developer directory created during SDK installation. A future SDK update could invasively modify that directory’s contents. Save your projects elsewhere. The name you assign to a new project will ripple through the project’s files in ways that will surprise the newcomer (you’ll get to see some of the implications later in this chapter). Although the name you assign at this stage does not have to stay with the app all the way to the App Store or to the app icon’s label in the home screen, I rec- ommend not trying to be too clever while thinking up a project’s name, especially if you have not yet figured out what you want to call the app in the App Store. By convention, project file names begin with an uppercase letter, although this is not an absolute requirement. One reason for this project naming convention is that Xcode generates some project files and objects beginning with the name you assign, and those files’ names typically begin with an uppercase letter. For multiple-word project names, I recommend using CamelCase formatting rather than spaces between the words. If you use spaces, Xcode will turn those spaces into underscore characters for the filenames it generates. For the Workbench project, assign the name Workbench and click Save. Welcome to Your Project After a little bit of churning, Xcode creates the new view-based project represented in the window shown in Figure 3-4. Let’s take a quick tour of the window, starting with important items in the toolbar at the top. Creating the Project in Xcode | 29
  • 52. If you have previously customized Xcode, the makeup, order, or labels of buttons and other items in the toolbar may look different from Fig- ure 3-4. If you clicked the clear “lozenge” in the upper-right corner, you won’t see a toolbar at all. Click it again to make the toolbar reappear. The Overview pop-up menu is where you select how Xcode should build and run the app. When it shows “Device” on the left side, it means that deployment will go to any iPhone-compatible device that is currently connected to your Mac via USB cable and designated as a development device (you will also need to be a member of the paid iOS DeveloperProgram).Duringmostofyourdevelopment,youwillbeintheDebugmode, and instead of loading the app onto a device, you will direct the app to load into Simulator. Continuing our tour of the toolbar, the Action menu contains commands that you may issue on items selected in the Groups & Files list below. Your interaction with this menu will likely be minimal, because most menu items are duplicated in the Xcode menu bar. Once you start writing code and wish to step through code while it runs, you will activate the Breakpoints button, which controls whether the next button reads Build and Run (ignoring breakpoints) or Build and Debug. Clicking the Build button in either form causes Xcode to compile your project and load the app onto a device or into iOS Simulator (depending on the Overview setting). Figure 3-4. The default Workbench project window 30 | Chapter 3: Creating a Test Workbench
  • 53. As you have probably experienced with JavaScript debuggers, you set a breakpoint in your source code by clicking in the column to the left of any statement. With breakpoints enabled in Xcode, program execution pauses at the designated line location. You can then step through your code while observing variable values and following logic paths in the separate Debugger window, available via Xcode’s Run menu. The lower-left pane, labeled Groups & Files, is where you organize the files of your project. Notice that the folder organization here is completely independent of the organization of actual files in your project’s Finder folder. The purpose of this pane is to let you collect all of the project’s external files into an organization that helps you locate the files for editing, especially as a project grows to potentially dozens of files. You can add groups (folder icons) as you go and change the organization at will; you may even nest groups to multiple levels if it helps you keep things straight. Most of your activity will be in the topmost group, whose name is that of your project. There- fore, at this stage, don’t be put off by the long list of other items, many of which you won’t deal with directly or regularly. By default, the upper-right pane lists the items contained by whichever group is selected in the Groups & Files pane. If an item’s name is shown in red, it means the file is expected but doesn’t exist yet (or has been deleted from the project’s Finder folder). For example, because you have not yet built the Workbench app, the compiled .app file (in reality, it’s a package) does not yet exist (although it is expected to exist even- tually) and is listed in red. If you select only a single file in the Groups & File list, that file is the only one shown in the upper-right pane. Don’t worry about the columns at the right at this point. Finally, at the bottom right pane is the editor window where you write and edit source code. It is more important to have a big editor window, and the upper-right pane’s contents aren’t that important during code creation. Therefore, drag the divider between the two right-hand panes upward so that you have only a single editor window, as shown in Figure 3-5. Editing Your First Files To display a source code file in the editor window, select the file from the Groups & Files pane. For Workbench, expand the Classes group and select the WorkbenchView- Controller.h file, the third one in the group, as shown in Figure 3-5 (you’ll learn about classes and the meaning of the .h and .m files in a later chapter). Xcode created all of the code you see here. The file begins with several lines of comments—yes, two forward slashes is one way to signify comments, just as in Java- Script. The comment lines include the name of the file and its owning project, as well as some identifying information, which Xcode has obtained from the system. You are free to edit comments as you wish, including adding more lines if you need them. Creating the Project in Xcode | 31
  • 54. You’ll begin editing this file by specifying the syntax for the method that will ultimately be triggered when you tap the button in the Workbench app. I’ve named the method runMyCode:. Objective-C method definitions begin with either a minus sign (−) or plus sign (+). Each sign has a specific meaning (described in Chapter 4), but for this method, use the minus sign. In the WorkbenchViewController.h file, insert the following code after the right curly brace, but before the line containing @end: - (IBAction)runMyCode:(id)sender; As you type, you’ll notice that Xcode tries to complete words automatically that it recognizes, such as IBAction. If you wish to accept the suggested autocompletion, press the Tab key, and the text insertion pointer zips to the end of the word. Just like JavaScript, Objective-C is case sensitive, so be careful with your typing. But unlike JavaScript, the semicolon at the end of a statement is absolutely required. Omitting a semicolon at the end of an Objective-C statement is like omitting the period at the end of an English sentence. As shown in Figure 3-6, when you make a change to a file’s contents, the icon for that file in the Groups & Files listing turns dark gray, signifying the file is “dirty.” Typing Command-S saves the file and restores the “clean” icon. Next comes editing the WorkbenchViewController.m file, where you’ll add the code that actually runs when the method is invoked. Click the WorkbenchViewController.m file in the Groups & Files listing to display the file’s contents in the editor pane. Then Figure 3-5. Editing the WorkbenchViewController.h file 32 | Chapter 3: Creating a Test Workbench
  • 55. Other documents randomly have different content
  • 56. all very interesting studies—the most unusual people he had ever known. But, as the evening wore on, dissipated by cards and gramophone selections, scraps of dancing executed fantastically by Mrs. Manton and the enamoured stranger, whose name he did not learn, he grew gradually weary of the desultory entertainment, and wished Lee would return. At length he came. After receiving warm welcomes from everyone present, he led Mauney up to his room. The hallway on the first floor was too dark to give any view of the place except that Lee’s room was at the front end of the corridor on the right side, and when illuminated was seen to be a large, comfortably furnished chamber with two windows facing Franklin Street, and a flat-topped desk placed between the windows. Upon the desk were a long row of large technical volumes, an ink-well, blotters and a ruler. There were two big, leather-upholstered, easy chairs in the outer corner of the room, facing each other, and a small smoker’s stand between them. Lee raised the windows to freshen the stale air, then turned in a general survey of the familiar place. “What do you think of the bunch?” he asked casually, as he lit a cigarette. “I like them fine,” said Mauney. “They’re quite clever, these people.” “Oh, yes. So they are,” Lee agreed, as he dropped wearily into one of the chairs and waved Mauney to the other. “Are you smoking?” Mauney raised his hand. “You know, Mr. Lee,” he smiled, “I’m just a green-horn from the country. I’ve had quite a lot of new experiences to-day already. I’m not snobbish about tobacco, but I’d rather leave that for another day or two, if you don’t mind.” “Fine,” laughed Lee. “You’ll get along in the world all right!” “Do you think so?” “Surely. You don’t need to take my word for it. I find that Gertrude is an extremely shrewd judge of men, and I’d like to tell you what
  • 57. she said about you—if you wouldn’t misunderstand her.” Mauney was greatly interested. “No, I won’t. I like her a lot. What did she say?” “Well, she said in the kitchen, while she was making those sandwiches, ‘Where did you get this big, refreshing country breeze, Max?’ I told her you were coming to the city for the first time to take up some kind of academic work, and she looked up at me as if surprised. ‘Clever kid,’ she said. ‘He walked right over to me like a confidence man at the start. I pretty near gave him my heart.’ Now, of course,” added Lee, “when Gertrude feels that way about anybody, he’s elected!” “How do you mean?” “Why, the house is yours. You can stay and board here. In other words, you gibe, fit in, dovetail—do you get me? I told her you might like to remain here, and she just nodded, which means that to-morrow night, without anything being said about it, a room will be ready for you to occupy.” “Do I pay in advance?” Mauney enquired. “No, no,” laughed Lee, as if at his friend’s inexorable ignorance; “you don’t do anything of the kind. She may not ask you for money for a month. Then she’s liable to suggest it very delicately, and, as a rule, you give her just a little more than it’s worth—see? You pay for atmosphere here and for her peculiar selection of other guests.” “How much should I pay a month?” “Oh, forty-five or fifty is what I usually contribute. And then, if you ever see any ice-cream or fruit or a new victrola record or anything in that line, down-town, you just buy it and bring it home as an occasional treat.” Mauney sat back in his chair and smiled. There was a flush of comfort in his face and a new relaxation. He liked the place, although he was still overcome, almost exhausted, by the swift changes of the day. Especially did he like Maxwell Lee, this
  • 58. comforting fellow with visionary dark eyes who sat opposite him now, smoking meditatively as if quite aware of the epoch-making significance of a simple railway journey; as if he realized how great an event it had really been to Mauney’s inexperienced soul. CHAPTER II. Mauney Prepares for College. “I consider it most becoming and most civilized to mingle severity with good fellowship, so that the former may not grow into melancholy, nor the latter into frivolity.”—Pliny the Younger, Ep. Bk. 8. When he awoke in the morning, he was vaguely conscious of some one talking in the room. Over the edge of his counterpane his eye caught the pyjama-ed figure of Lee, shaving in front of the dressing-case mirror, and he soon realized that Lee was talking to him. “—thinking it over,” Lee was saying. “And I believe your best stunt is to look up a tutor who will give you your matriculation work extra- murally. That won’t tie you down to any formality of going to a high school. You can work as hard as you like, and, at your age, you’ll clean up that preliminary dope just like ice-cream.” Mauney sprang out of bed and shaved. He fell in with Lee’s suggestion and decided that he would look up a tutor that very morning. He was thrilled with excitement and happiness. Outside the windows, rain was splashing on the sills, but it was the merriest, gladdest rain he had ever listened to. Before him stretched the great adventure of education, rich in its promise of compensation for all the years of miserable waiting. In fact, could it be quite true that he was actually conscious? Was he not rather treading the air of a delightful dream, from which, at any moment, he would awake to bleak realities?
  • 59. There were only three at the breakfast table when they descended —Mrs. Manton, seated at the end in a rich dressing gown of yellow silk, and Jolvin, with Stalton, at one side. The Englishman, fully dressed as for business, ate in dignified silence. Stalton, whom to know was to love, sat in his shirt sleeves without a collar, as if he had no other business in life than to act in the capacity of a cross- corner mentor for his landlady. Mauney was assigned to a place between the two men, while Lee sat down at the opposite side. “It’s a grand morning, Mr. Bard,” said Stalton, as he poured some medicine into a spoon from a large bottle by his place. Perhaps, thought Mauney, Stalton’s gray hair and flabby grey face were evidence of some chronic ailment—the wearing effects of pain. He felt sorry for his table companion. “Hello,” laughed Lee, glancing across at the bottle, “What are you taking now, Freddie?” “This is a new consignment of dope, Max,” he replied good- naturedly. “It’s guaranteed to contain the real wallop. Made up of yeast, raisins, vitamines and monkey glands. Don’t be surprised to see me challenging the heavy-weight champion next spring.” Jolvin, whose mind at the moment may have been grappling with serious business problems, was evidently irritated by Stalton’s remark. Suddenly his face whirled directly about toward Mauney, who nearly jumped with astonishment. “For God’s sake,” whispered Jolvin, “I wish he’d stop that stuff at breakfast.” Then his head snapped back to receive the last spoonful of his cornflakes. “One would fancy,” he said aloud, “it would stop raining!” “Yes,” murmured Stalton. “One would. But I guess there’s a few bucketfuls left up there yet.” “How’s the tooth this morning, Freddie?” enquired Miss Grote, as she walked into the room. “It’s still in my head, Sadie, but I expected it would jump out, about two this morning.
  • 60. “For God’s sake,” whispered Jolvin into Mauney’s ear; “he can’t talk about anything, but teeth—teeth!” He made a nervous stab at a rasher of bacon and cleared his throat. “I fancy,” he said aloud, “we’ll be getting some prime weather after this!” “Yes, no doubt,” replied Stalton. “This rain ought to prime anything, including the cistern pump.” Mrs. Manton cast a reproving look at Stalton, shook her head hopelessly, sighed, and continued her breakfast. Mauney, in the best of spirits himself, unconsciously cast his sympathy with Stalton. “Did you hear the rain on the roof last night, Mr. Stalton?” he asked, by way of making conversation. “Sure thing.” “Did it help you to sleep?” “It doesn’t affect me like that, Mr. Bard,” he answered. “Unfortunately I passed through a period of my life when I had the rain without the roof, and rain ever since brings up the past. And then, in this kind of weather my teeth are always—” “For God’s sake,” exclaimed Jolvin aloud, bolting from the table, stamping indignantly into the hall, and presently banging the front door behind him, as he left the house. “What’s wrong with that long drink?” purred Mrs. Manton. “He’s just acting natural,” Stalton said. “I knew he got out of bed over the foot. He’s had more hard luck with his uncle’s estate in England, too, and I knew he’d scoot if I said anything more about teeth.” “Well, he can tame himself,” Mrs. Manton submitted calmly. “This is not an institution for the nervous, and if Jolvin doesn’t like it, he’ll discover that there aren’t many invitations out to remain.” “These fits of his are getting more frequent,” Stalton remarked.
  • 61. “He’ll have to mix his drinks a little better than that anyhow,” said the landlady. “Don’t you think so, Max?” “It takes all kinds of people to make a world, Gertrude.” Lee reminded her. “I feel so darned cut up about my biochemistry, I can’t be expected to give an unbiased judgment.” “Poor boy. You’ll get it, all right. When do you write?” “This morning.” Mauney accompanied his friend, whom he began to address now as Max, down to the university and, after Lee had disappeared into one of the buildings, stood thrilled by the spectacle before him. Here, surrounding the square, reposed the exemplary specimens of architecture that housed the various faculties. Max, in leaving, had pointed them out hurriedly—medicine, industrial science, Methodist theology, the great library, the convocation hall, the gymnasium, and last, but most impressive, the arts building, a solid, reposeful mass, as sure as learning itself, with its vine-dressed, dull grey walls of stone, it’s turreted tower, its marvellous gothic entrance, leading from the common day, past its embellished arch, into the dim twilight of contemplation. The square was belted by a gravel road, serving the various buildings, and was itself divided into eight triangular lawns by wide cinder paths, crossing from side to side and from corner to corner. It was a pleasant view, for the art of the landscapist had relieved the conventionality of the pattern by maples and ash-trees, distributed over the lawns, and by clusters of spiræa and barberry set attractively at the edges of the paths. The square was nearly deserted, save for one or two students who sat on the benches reading. Mauney wished that with the fall opening he could be ready to enter upon his college course, but, knowing this to be impossible, turned sadly away, but yet with burning ambition, to find the tutor whom Max had recommended. He was discovered in a little office on College Street, a small, withered individual, almost swallowed up in the cluttered disorder of his administrative quarters. His yellow face,
  • 62. creased like old parchment, bent into a mechanical smile as he listened to Mauney’s desires. For a moment he fingered the paper- knife on his desk, then cast a weary look at his young customer through tarnished silver-rimmed spectacles. “The matriculation requirements, Mr. Bard,” he said, in a cultured, but infinitely dreary voice, as if repeating a stereotyped speech, “are becoming increasingly onerous. The departments of the University of Merlton have established rather severe standards for college entrance, and I fear you will experience disheartening difficulties in attempting to gain matriculation status within the limits of a single winter term. However, your ambition is indeed commendable and, with perseverance, combined with extra tutoring, you may perhaps be able to succeed. The course that I would recommend”—he reached for a folder and, opening it, ran his yellow forefinger down its pages—“is partly a correspondence course, but partly, also, one of personal supervision, especially in science subjects. The cost of this course is considerable, but I am glad to be able to quote an average of sixty per cent. successes over a period of the last fifteen years. Other preparatory tutors have not, unfortunately, been able to compete with these figures. The fees are payable strictly in advance, and if you decide to embark upon the course, you are promised the same individual, careful attention that is given to everyone.” Mauney questioned nothing, but embarked. He was almost delirious with happiness over the proceedings, the enrolment, the purchase of a score of interesting books which the tutor recommended, and the prospect of commencing so quickly the life for which he had longed. His room at seventy-three Franklin Street, next to Max’s, was soon a student’s den, with its own table, its own volumes and its easy chairs. His life became a very pleasant thing, for, with his daily visits to the little office on College Street, and the diversions of the boarding house, he found what seemed to him a wealth of variety. He was astonished at his own contentment and at the self-sufficient quality in him that scarcely, if ever, caused him to think of his former home, or to reflect upon the dearth of relatives in his new existence. He wrote to his aunt in Scotland, expressing high
  • 63. satisfaction with his present occupations. He settled down in the loved quietness of his room, to master the rudiments of education. Never once did he stop, weary, for with the sharp appetite of a starved mind, he thought of nothing but more information, and more. Max, who had been successful in his supplementary examination and was now engaged in the fourth year of his medical course, frequently dropped into Mauney’s room for a smoke and a chat. Max never spoke about his own home, and Mauney refrained from questioning him. The basis of their friendship was something personal and gloriously indefinite, that neither thought of analyzing. They felt at home with each other, and never, from the very beginning of their acquaintance, did anything disturb this quite unaccountable understanding. Mauney always felt that there was a hidden thought at the centre of Max, with which some day he would be favored, for behind his dark and often weary eyes great dreams seemed to pass, greater than the drawl of his clever and sarcastic tongue. He ventured to think that perhaps Max had drifted into a profession for which his nature disqualified him, for he naturally gained the impression that a medical student needed to be, in one particular sense, a feelingless person, with certain vulture-like qualities to steel him against the revoltingly physical aspects of his work. The skull in Max’s wardrobe, the illustrations in his books— there were many symbols of the idea. In secret, however, Max was evidently no materialist, but sought the wide comfort of philosophic generalities. No one, to be sure, would suspect it at seventy-three Franklin Street, where he was known by his smile, but Mauney would catch the plaintive note in some quiet remark, as when one evening, in discussing college work in general, he said: “Wrap up your colleges and throw them in the ocean. They furnish us a few years of diversion, but after that there’s life, and, strange to relate, Mauney, my son, they have not prepared us for that.” Mauney excused such criticisms of the university on the basis of a personal warp in Max’s character, forgave him for what seemed a
  • 64. vandal attitude, and went on believing more firmly than ever in the light that spread from the lamp of learning. By its flame, comforted and inspired, he forgot the passage of time. He failed to notice the blush of late autumn that swept like a passion over the trees of the city, scarcely saw their bare arms raised in supplication to the greying skies, nor heaven’s response of swift winds carrying fleecy burdens. Not until the firm banks of snow began to settle down, smaller and smaller, under the warming suns of a windy March, and energetic streams of murky water rushed along the street gutters, did he wake from his steadfast dream to realize that his term was nearly over. Then came a sharp bout with the examinations and at the end of May he stood looking curiously down at the withered old tutor who was smiling less stiffly, less professionally, than usual. “I am pleased to tell you,” he said, “that you have gained your university entrance standing. Your work with me in the preliminary subjects has been, to say the least, good, and it will afford me pleasure to produce documentary evidence of your success.” He paused to reach a small certificate from a drawer. “This,” he continued, handing it to Mauney, “should be carefully preserved and forwarded to the university in making your application for admission thereto, sometime before September.” “Thanks.” “And before you go,” said the tutor, rising stiffly from his chair, “let me express the pleasure I have had in overseeing your early academic career. Moreover, I would be interested to learn what particular course you contemplate taking at the university.” This was a new idea to Mauney. He looked at the instructor for a moment, with a perplexed expression. “I’m much interested in people,” he said, “and I think if I could get a course in history it would suit me.” “Remember,” cautioned the old man, lifting his finger as if admonishing a wayward son, “history is a culture course which, from the financial standpoint, leads you nowhere. It would fit you only for
  • 65. teaching, a profession which, as I have learned from acrid experience, is not perfectly appreciated by the public. You have other courses to choose from, the more practical ones, as they might be called, such as engineering, law, medicine.” “Well, I’ll have to consider the question,” Mauney replied. “Just so. In the meantime, I would be glad to advise you on any points and to see you, from time to time, in order to learn of your academic progress.” There was a light almost of kindness in the wrinkled, yellow face as he bade him good-bye. Mauney did not know how seldom that light had been there under similar circumstances, nor did he know that the affection of the old tutor was the same kind of affection that he unconsciously inspired in most of his associates. Burning with gleeful happiness over his success, he hurried home to tell Max. “Well, you old bear!” exclaimed Lee, violently shaking Mauney’s hand on learning the news. “You couldn’t have done better. I’m as happy as if I’d done it myself.” “Behold the hero,” Max said, as they went into supper together. “He’s just laid ’em all out. Four years’ work in one.” “Hurrah!” shouted Mrs. Manton, putting her arms about Mauney’s neck and kissing him prettily on the cheek. “I knew you’d do it, Mauney,” she said. “Maybe you did, Gertrude,” he laughed, trying to cover his embarrassment, “but I didn’t expect that. However, don’t think I didn’t like it.” Even though Mrs. Manton’s impulsive embrace was decidedly consoling, Mauney nevertheless disliked it. He felt immediately afterwards that he would increase his diligence to detect her next time before it was too late. He accused himself of being perhaps by nature too cold. But from the evening, some years since, when he had felt a woman’s hand upon his own, he had disliked the feeling. A woman’s hand was too soft. It reminded him unavoidably of a snake,
  • 66. and made him shiver. This thesis ran through his private thoughts a good deal. He did not know women. He thought they were rather pleasant beings at times, but the danger of having their warm, soft hands suddenly upon him, inspired an attitude of caution. He felt confident of managing them in conversation, but confidence flew to the winds at the approach of hands, or arms, to say nothing of lips. The summer months passed with snail-like tardiness. Having no place in particular to go, and nothing in particular to do, he remained in Merlton at his boarding house, and divided his time between reading and making excursions on foot, exploring the city. He now seized his first opportunity to gratify a long desire, and spent many of his mornings on the river. Max, who had this time passed his annual examinations without stars, had gone out west to teach school for the summer, in order to make enough money to finance his final year in medicine. The balance of the personnel at the boarding house remained unchanged, until one morning at breakfast he learned that Jolvin was about to return to England. The news came from Stalton, who said he had been talking to Jolvin the night before. “Gertrude,” he said, “do you know what’s happened to that bird? He’s fallen into a big estate—his uncle’s estate. Why, it’s worth a couple of hundred thousand. I saw the lawyer’s letter last night. What do you know about that?” Mrs. Manton ate in silence for a moment. “Do Jolvin’s socialistic beliefs prevent him from accepting it?” she asked. “Not very much!” Stalton replied with sarcastic emphasis. “And, by the way he was talking last night, he’s forgiven England for being such a dough-headed outfit. Why, that fellow came out here two years ago like an understudy of Columbus. England? Not if he knew it. And now I’ll bet he gets the first boat home. Just watch him skidaddle.”
  • 67. It was not many minutes until Jolvin, the centre of conversation, came down to breakfast, unusually smart, his face wreathed in smiles. “Good morning, people!” he said expansively, with a very full bow. “Isn’t it a lovely morning? Good-morning Stalton!” “How do you do?” said Stalton crisply. After taking his seat, the Englishman, noticing the silence of the table, thought perhaps to stir up conversation. “You know,” he began, glancing at his dish, “these corn-flakes are really beastly grotesque things. In England one scarcely sees them. They are, I fancy, an expression of American commercialism which invades even the time-honored ritual of breakfast.” Stalton suddenly dropped his spoon on the table. “Well, I’m damned,” he said, simply, and once more took up his spoon, having received a stern look from Mrs. Manton. Jolvin appeared not to have heard Stalton’s remark, but continued, “But, of course, America is too busy to cook porridge. There is no leisure or time for what one might call a comfortable dignity.” “All this don’t jibe very well with what you usually say about England,” Stalton remarked. “Most of the time you seemed to hate the word.” “Not at all,” argued Jolvin. “Any criticisms I have ever made of England were meant most heartily. But they were criticisms, not blasphemies. If I were indifferent to England, I should never bother even to criticize.” “Have it your way, Jolvin,” said Stalton. “But you were always damning the leisure class. Now you’re praising them.” “I still damn them for their faults. Why, then, should I not praise them for their virtues?” “Sail right ahead,” invited Stalton. “You’re in good form this morning. Got me outclassed, that’s a cinch.”
  • 68. Even without Jolvin the place was still a most unusual boarding house. Mauney had learned, by this time, some of its tacitly- established principles. In the first place Mrs. Manton, at thirty-five, being widowed as was understood, regarded her house as a master hobby. Great attention was bestowed upon the furniture, the rugs and the walls. She wanted her guests to be comfortable and, to that end, would put herself about unceasingly. No advertising of vacant rooms was ever done, for it was better to have an empty room without a monthly revenue, than a full room with an unknown, undesirable stranger. Certain standards had to be satisfied. Mrs. Manton’s boarders had to possess what she tersely designated as “savez.” This meant a number of things. It meant the faculty of living in harmony with other boarders, of being informally polite and not impolitely formal. It meant keeping in the background all grandiose ideas, but at the same time indulging in enough conversation to register one’s consciousness. It meant that one should not comment upon the doings of others, but at the same time that one should avoid doing anything to invite comment. It meant even this, that if one’s breakfast were not placed before him as quickly as desired, he was expected to go to the kitchen and get it; or if one’s bed was not made up, the understanding was that it be made up by oneself. And finally, of course, that after a few days’ residence as an introduction, one would notice that the landlady was to be addressed familiarly as “Gertrude.” Mrs. Manton preferred men to women boarders. Mrs. Dixon was permitted because her husband was a good sort, with funds of information about racing horses and the track in general. Sadie Grote, a stenographer down town, was agreeable and sweet, very unselfish and therefore helpful. Women had often been under consideration. At one time Mrs. Manton conducted an experiment by letting the whole top flat to four university girls. They remained a whole term, but when the last of their baggage had left the front door in the spring, Mrs. Manton had turned to Stalton with all the impatience of a disappointed experimenter.
  • 69. “Freddie,” she had vowed, “never again! If we ever have girls, they’ve got to have blood in their veins, not pasteurized milk. Isn’t it pitiful how that dreadful disease known as brain-wart seems to get them.” There was no gainsaying it—eligibility to seventy-three Franklin Street required unusual, indescribable qualities. If Mrs. Manton had written down rules of conduct (which, of course, she never did), and hung them on the wall, they would have read much as follows: “1.—Avoid extremes. “2.—Nourish high-falooting ideas, if you wish, but keep them under your hat. “3.—Be as happy as you choose, but don’t explode with nauseous hilarity, since somebody else may be sad. “4.—Be downcast when you must, but don’t spread your gloom. “5.—Be erudite, but don’t teach your ideas. “6.—Be chuck-full of anything you choose to be chuck- full of, but sit on it. “7.—Remember that seventy-three aims at averages, prefers neutral tints and the soft pedal. “8.—Don’t effervesce—most of us have passed that stage. “9.—Don’t criticize—we all have to live. “10.—Live, but don’t plan. To-day was to-morrow, yesterday.” Mauney felt unlikely to transgress many of these tacit rules of conduct. He was quiet enough in disposition to melt into the quiet shadows of the place, and was fond enough of the inhabitants to
  • 70. pattern his superficial manners after theirs. But he well knew that there was danger of breaking one of the rules. He had not yet passed the stage referred to in number eight, and was quite liable to burst forth enthusiastically to some one. His enthusiasm for his books and the sheer happiness he obtained from them was dangerously concealed. It troubled him. He wanted to talk to Max Lee, and longed for his return. Then, too, the present, though charming, was so incomplete! The others at the boarding house truly lived for the present moment, but Mauney was feeling the great future beating like a pulse. He was standing like a benighted sailor on the dark coast, feeling the break of waves he could not distinctly see, and coveting the dawn when all would be revealed. CHAPTER III. The Other Half of the Class. “A morning sun, and a wine-bred child and a Latin-bred woman seldom end well.”—Herbert’s Collection. Mauney met Lorna Freeman the first day of college. He did not know her name at first, but she impressed him. This was partly because certain grooves, instituted that day, promised to guide her in his company for the next four years, brilliant in prospect. It happened that out of the great University of Merlton, only two first year students had chosen the “straight” history course. Many others had elected to take combined courses of history plus something else or other, but of the entire academic population of the first year only two showed the real specialist thirst for history alone. This meant that they would receive much that the others would not. They would be inducted more deeply into the records of human development. They would be together, a class all by themselves, at times, penetrating further than the dilettanti, who stopped with
  • 71. constitutional history of Germany. For these two out-and-out students there would be interesting journeys afield. He faced Lorna Freeman, therefore, with at least the vague knowledge that they two were the real, serious history class. They enrolled together with the assistant professor of history, Dr. Alfred K. Tanner, M.A., Ph.D., D.C.L. (and other degrees usually taken for granted), in his particular upstairs office in one of the wings of the Arts Building. Miss Freeman had already submitted her name, just as any other student might have done, although there were reasons, as shall be seen, why it was superfluous. There were a score of students outside Dr. Tanner’s door, waiting to be enrolled. But they were the part-timers, the non-specialists, the great unwashed. First attention must be given to the “straight” students, and Alfred Tanner had already given his attention to Lorna Freeman, had waved her to a stiff chair by the mullioned windows, and was now giving his attention to Mauney. He was a big, energetic figure, even as he sat behind his flat- topped desk, with a look of keen awareness mixed with love of his work. He was grey, and bald, and hugely present. He leaned forward, gesticulating, snapping his grey eyes eagerly. “Your name is what?” he asked. “Bard.” “Bard, yes, Bard. What else?” he mumbled, as he wrote it down. “Mauney.” “Mauney, yes; Mauney Bard! I see!” he looked up to subject Mauney to a severe scrutiny, during which he was absent-mindedly biting the nail of his little finger. “And now, tell me, Mauney Bard,” he said suddenly, aiming his plump forefinger at his new pupil, “Tell me, as well as you can— that’s to say offhandedly—tell me exactly why you elected the straight history course?”
  • 72. As he waited for an answer, he looked frowningly toward the window, rubbed his nose, and held his head like a musician preparing to judge the quality of a chord of music. “I would say the reason is simple enough,” said Mauney. “Good,” commended Tanner, hammering the desk with his fist: “Simple enough? Yes? Good. All right, Bard; explain that. Tell me exactly why you elected it?” “Because,” said Mauney deliberately, “I’ve always wanted to understand the basic principles of human progress.” Tanner, still frowning at the window, mumbled in an absent- minded tone: “‘Basic principles of human progress.’ Yes; basic principles.” Then, turning suddenly toward Mauney, he once more aimed his finger like a pistol at his face, while his voice came out with great clearness and deliberation: “Good for you. That’s good, Bard, very good. Now, you will consult your time-table to find out your classes, and, by the way, it’s a very small class this year.” He turned toward the young lady seated by the window. “Lorna!” he said. “Yes! Uncle Alfred,” she responded, in a clear voice, rising and gracefully approaching the desk. “This is Mauney Bard—Miss Freeman!” “How do you do,” she said, with a faint smile and a nod of her head. As Mauney bowed to her he noticed what clear, blue eyes looked fearlessly into his—calm, quiet eyes, with almost a suggestion of challenge. She was in a grey street costume that clung neatly to her spare, trim form, and wore a wide-rimmed black hat that sat smartly upon her blonde hair and emphasized the natural pallor of her face. Her features were regular—a straight, refined nose, and thin, pretty lips. Her hands were extremely white. In different attire she could have played a part in a tableaux of the vestal virgins. She gave
  • 73. Mauney the same feeling as he had often experienced on looking across the meadows in the white light of a dewy dawn. “You and Mr. Bard are the class,” laughed Dr. Tanner. “I hope that a friendship of reasonable rivalry may exist in the class, at all times, and that we will be able to find a room somewhere small enough to hold us.” “I know a good place, Uncle Alfred,” said Miss Freeman. “Where, then?” “In the tower.” “Well, we shall see, Lorna. We shall see. I don’t like it myself, but your suggestion merits consideration. H’m! The tower? Why on earth, my dear child, do you say the tower?” “It isn’t in use.” “No. Neither is the furnace room.” “But the tower would give one such a philosophical elevation, just like old Teufelsdrockh in Carlyle’s book.” “Oh, damn Carlyle!” “Uncle Alfred!” “Excuse me, Lorna,” he laughed mischievously. “Well—a place will be found. Now, you two, clear out. There’s a congregation of pilgrims near by, seeking the shrine of Magnus Apollo.” Mauney did not know that the young lady with whom he walked down the worn stone steps of the history department was the daughter of Professor Freeman of that same department, whose office they passed on their way to the square. That was to be learned later. He only knew that she seemed an exceptionally fine person. “Isn’t it funny,” he remarked, as they passed through the long corridor of the Arts Building. “That there should only be two of us in the class.”
  • 74. “No, I don’t think it’s funny,” she said. “I mean remarkable,” he corrected himself. “Well, it’s a small class, certainly,” she admitted. “There are few people who elect history as a straight course in Merlton, I believe. There should be more. I had wished there would be at least another woman.” “That would have made it pleasanter for you, Miss Freeman.” “Naturally.” Mauney noticed how little deference her manner contained. After he had left her at the front entrance and was on his way home, he wished that she had said: “Oh, I think we’ll get along all right.” But she had frankly admitted that another woman in the year would have made it pleasanter for her. Queer little blaming thoughts rose up in his mind against her. Then his thoughts changed. He began to admire her attitude. She had been absolutely frank. Was that not rather unusual? Was she not an unusually truthful kind of girl? Presently he lost all touch with the argument. His brain was painting pictures of her, in dignified poses, representing some abstract idea of virtue. Finally he checked the images and cursed himself for being such a susceptible person. Miss Freeman was merely a member of the class. Half the class had no right to be thinking such thoughts of the other half. Nevertheless Mauney’s first impression of university life was an impression of a woman, the first woman, in fact, who ever seriously disturbed his thoughts. That night he went into Max Lee’s room to have a smoke. Max was tired after his summer of teaching, and was viewing the fifth and last year of his course with evident distaste. “Sit down, Mauney, my son,” he invited. “There’s some good cigarettes. I’m glad you’re taking to smokes. It will make things evener between us. Well, how’s things?” “Not bad, Max,” he replied, taking one of the easy chairs. “I got enrolled to-day, but haven’t seen much of the university life yet. The
  • 75. assistant professor of history, Dr. Tanner, is a good fellow. I’m going to like him. He’s got a big-brotherly sort of way with him, and I hope he lectures to us. I didn’t see the professor yet. I suppose he’s too important for a mere first-year man to meet so soon.” “How many are in your group?” “Just two. Myself and a young lady, whom I met this morning in Tanner’s office. Her name is Freeman—rather a good-looking person. She and I are apparently booked up together for a four-years voyage.” “In that case,” smiled Max, “I hope she’s companionable.” “Well,” he replied very seriously, “that’s doubtful. I wish there was another man along—somebody I could swear at when I felt like it. I’ll make the best of it. She may be a really fine person. She’s a niece of Tanner’s, too. When do you start work?” “To-morrow. Fifth year is pretty easy, but I wish it was over. I’m getting sick of the whole game.” “What’s the matter?” “Money, of course.” “Do you mean you’re short of cash?” “Sure. It’s going to be tough wiggling to get through this year,” he admitted. “Do you know, lack of money is the one, big, damned tragedy of my life?” “Could I lend you some?” Mauney asked simply. “Could you—what?” exclaimed Lee, sitting up. “Have you got money?” “Some,” admitted Mauney. “I could lend you a few hundred, if you need it.” “It’s mighty decent of you, boy,” Max said. “But I couldn’t accept it.” “You don’t need to feel that way.”
  • 76. “But I do nevertheless. No, I couldn’t. That’s all.” “Will you promise to let me know if you need it, later?” “Look here,” said Lee, settling back in his chair wearily. “I mentioned money only to dismiss the topic. I have no desire for wealth, and it’s not immediate needs I’m thinking of. But here I am, fagged, at the start of my last year. When I get my M.D. I’ll be as far from making money as I am now. It’s getting to be an up-hill game, you see? There are certain things that a fellow wants to do some time before he dies, and getting married is one of them.” “Yes,” said Mauney; “I suppose that comes into the scheme of things.” “The scheme of nothing!” scoffed Lee. “It simply gets into your blood when you meet the right woman.” “Am I to suppose,” asked Mauney, in a teasing tone, “that you have met her?” Lee was silent. His dark eyes were seriously looking into space, while his cigarette burned slowly between his fingers. Mauney realized that he had trampled carelessly on holy ground, but allowed his own silence to be his only apology. “We’ve known each other long enough, Mauney, to understand how things affect us individually. I’ve never mentioned women to you. But there has been one, all along—this past year. She’s real. I love her, but I can’t tell her. She regards me only as a friend, and I wouldn’t let her know how I feel for anything.” “You may wonder why I wouldn’t,” he continued. “Well, it’s like this, I’ve made up my mind to go into research work next year, if my health remains good, and that kind of work won’t give me a living, let alone enable me to marry. She’s a girl who deserves happiness. Some one else will give it to her—not me.” “But the future may be brighter than you think, Max.”
  • 77. “I’m not a pessimist, Mauney,” he said thoughtfully, leaning his head away back and closing his eyes. “I keep up a cheerful front most of the time. But I know—I simply know that I’ll never marry Freda MacDowell.” “What is she like, Max?” “I’ll have you meet her some time. She’s just like nobody else.” The opening days of college dragged slowly for Mauney. There were broken classes, time-tables not yet perfected, initiations and other interfering details. Then, as if suddenly, the great university wheel quivered to a start and immediately swung around with remarkable smoothness and astonishing rapidity. In the daytime he sat listening to interesting lectures. In the evenings he lived with his books, deeply absorbed, as the weeks passed, with the problems of history. The records of human progress drew him with a warm, romantic attraction, for his imagination filled in the gaps that make history different from story. Characters became real and living. He rose and fell in sympathy with the dim fortunes of forgotten men. The formal page, with its caption and its paragraphs, faded into invisibility, leaving a glowing passage of actual life in which he brought himself temporarily to live. It was very engrossing. Lorna Freeman found it so, too. She grew somewhat more friendly as the weeks passed, and by mid-term she would talk volubly with Mauney on historical subjects. He found her mind to be an acutely exacting one. It surprised him at first to discover such a mind in a woman. He thought her mental powers exceeded his own, because she could nearly always trip him up in an argument, a thing which she habitually did without exultation, but just methodically, as if tripping him up were part of her natural occupation. One day he learned that her father was Professor Robert Freeman, the seldom-seen head of the department. Mauney only saw him once, as he was pointed out walking thoughtfully through the corridors, a small, shrewd-appearing man, with grey eyes and a fixed smile.
  • 78. History was absorbing, but our young hero was finding himself a good deal in thought about Lorna Freeman. Not once had he ever said a thing even faintly familiar. One Monday morning, however, the temptation became unduly strong. Miss Freeman was seated in the seminary room by the long table, waiting for Dr. Tanner to take the class. It was winter, and her fur coat was laid neatly over the back of an empty chair. She never removed her hat, a prerogative gained from the intimate size of the class. As Mauney entered the room she looked up from a book and nodded. “Good morning,” he said, as he took a chair at the opposite side of the table. The large Gothic window at the front of the room commanded a view of the square, busy with students hurrying in various directions to their lectures. Dr. Tanner was late. They sat for fully a quarter of an hour, she quietly reading, Mauney stealing occasional glances at her pensive face. He tried to categorize Lorna Freeman, but could not. She did not fit into any types existent in his mind. She was definitely unusual. She attracted him on this account. There was also about her a certain queenliness. Why had they never once found anything to talk about except their work? “I guess Dr. Tanner has been waylaid,” he ventured at length. “He’s usually so punctual, too,” she replied, and then continued reading. “Do you ever get tired of studying?” he went on, determined to sound her. “Well, naturally. Don’t you?” “I certainly do. I suppose if there was another man in the class I wouldn’t mind it so much.” She glanced quickly up. “Mind what, Mr. Bard?” “Well, you see, Miss Freeman, perhaps there’s something else in life besides continual study. I’d like to have somebody to chew the rag with, once in a blue moon.”
  • 79. Welcome to Our Bookstore - The Ultimate Destination for Book Lovers Are you passionate about books and eager to explore new worlds of knowledge? At our website, we offer a vast collection of books that cater to every interest and age group. From classic literature to specialized publications, self-help books, and children’s stories, we have it all! Each book is a gateway to new adventures, helping you expand your knowledge and nourish your soul Experience Convenient and Enjoyable Book Shopping Our website is more than just an online bookstore—it’s a bridge connecting readers to the timeless values of culture and wisdom. With a sleek and user-friendly interface and a smart search system, you can find your favorite books quickly and easily. Enjoy special promotions, fast home delivery, and a seamless shopping experience that saves you time and enhances your love for reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookgate.com