100% found this document useful (1 vote)
26 views

Learning iPhone Programming From Xcode to App Store 1st Edition Alasdair Allan instant download

This document provides information about the book 'Learning iPhone Programming From Xcode to App Store' by Alasdair Allan, which serves as a guide for those looking to develop applications for the iPhone and iPod touch. It covers various topics including Objective-C programming, app development processes, and distribution methods. The book is aimed at individuals with some programming experience who are new to iPhone development or transitioning from Mac programming.

Uploaded by

gesodbagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
26 views

Learning iPhone Programming From Xcode to App Store 1st Edition Alasdair Allan instant download

This document provides information about the book 'Learning iPhone Programming From Xcode to App Store' by Alasdair Allan, which serves as a guide for those looking to develop applications for the iPhone and iPod touch. It covers various topics including Objective-C programming, app development processes, and distribution methods. The book is aimed at individuals with some programming experience who are new to iPhone development or transitioning from Mac programming.

Uploaded by

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

Learning iPhone Programming From Xcode to App

Store 1st Edition Alasdair Allan pdf download

https://ebookname.com/product/learning-iphone-programming-from-
xcode-to-app-store-1st-edition-alasdair-allan/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Learning iOS Programming From Xcode to App Store Third


Edition Alasdair Allan

https://ebookname.com/product/learning-ios-programming-from-
xcode-to-app-store-third-edition-alasdair-allan/

Building iPhone Apps with HTML CSS and JavaScript


Making App Store Apps Without Objective C or Cocoa 1st
Edition Jonathan Stark

https://ebookname.com/product/building-iphone-apps-with-html-css-
and-javascript-making-app-store-apps-without-objective-c-or-
cocoa-1st-edition-jonathan-stark/

Learning iPhone Game Programming A Hands on Guide to


Building Your First iPhone Game 1st Edition Michael
Daley

https://ebookname.com/product/learning-iphone-game-programming-a-
hands-on-guide-to-building-your-first-iphone-game-1st-edition-
michael-daley/

Straight A s Are Not Enough Learning With Your Brain


Turned On 1st Edition Judy Fishel

https://ebookname.com/product/straight-a-s-are-not-enough-
learning-with-your-brain-turned-on-1st-edition-judy-fishel/
Basics Architectural Photography 1st Edition Michael
Heinrich

https://ebookname.com/product/basics-architectural-
photography-1st-edition-michael-heinrich/

Modeling Performance Measurement 2005th Edition Wade D.


Cook

https://ebookname.com/product/modeling-performance-
measurement-2005th-edition-wade-d-cook/

The Concept of Education International Library of the


Philosophy of Education Volume 17 1st Edition R. S.
Peters

https://ebookname.com/product/the-concept-of-education-
international-library-of-the-philosophy-of-education-
volume-17-1st-edition-r-s-peters/

Listening Is an Act of Love A Celebration of American


Life from the StoryCorps Project 1st Edition Dave Isay

https://ebookname.com/product/listening-is-an-act-of-love-a-
celebration-of-american-life-from-the-storycorps-project-1st-
edition-dave-isay/

Interpreting and the Politics of Recognition The IATIS


Yearbook 1st Edition Christopher Stone

https://ebookname.com/product/interpreting-and-the-politics-of-
recognition-the-iatis-yearbook-1st-edition-christopher-stone/
Principles of Foundation Engineering Si Edition Braja
M. Das

https://ebookname.com/product/principles-of-foundation-
engineering-si-edition-braja-m-das/
Learning iPhone Programming
Learning iPhone Programming

Alasdair Allan

Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo


Learning iPhone Programming
by Alasdair Allan

Copyright © 2010 Alasdair Allan. 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].

Editor: Brian Jepson Indexer: Seth Maislin


Production Editor: Sarah Schneider Cover Designer: Karen Montgomery
Copyeditor: Audrey Doyle Interior Designer: David Futato
Proofreader: Kiel Van Horn Illustrator: Robert Romano

Printing History:
March 2010: First Edition.

O’Reilly and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning iPhone
Programming, the image of a lapwing, 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.

TM

This book uses RepKover™, a durable and flexible lay-flat binding.

ISBN: 978-0-596-80643-9

[M]

1267461377
Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

1. Why Go Native? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
The Pros and Cons 1
Why Write Native Applications? 2
The Release Cycle 3
Build It and They Will Come 4

2. Becoming a Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Registering As an iPhone Developer 5
Enrolling in the iPhone Developer Program 7
The Apple Developer Connection 8
Installing the iPhone SDK 8
Preparing Your iPhone or iPod touch 11
Creating a Development Certificate 12
Getting the UDID of Your Development Device 14
Creating an App ID 15
Creating a Mobile Provisioning Profile 16
Making Your Device Available for Development 17

3. Your First iPhone App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19


Objective-C Basics 19
Object-Oriented Programming 19
The Objective-C Object Model 21
The Basics of Objective-C Syntax 23
Creating a Project 23
Exploring the Project in Xcode 25
Our Project in Interface Builder 32
Adding Code 34
Connecting the Outlets in Interface Builder 36
Putting the Application on Your iPhone 37

v
4. Coding in Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Declaring and Defining Classes 41
Declaring a Class with the Interface 41
Defining a Class with the Implementation 42
Object Typing 43
Properties 44
Synthesizing Properties 45
The Dot Syntax 45
Declaring Methods 45
Calling Methods 46
Calling Methods on nil 47
Memory Management 47
Creating Objects 47
The Autorelease Pool 48
The alloc, retain, copy, and release Cycle 48
The dealloc Method 50
Responding to Memory Warnings 50
Fundamental iPhone Design Patterns 50
The Model-View-Controller Pattern 51
Views and View Controllers 51
The Delegates and DataSource Pattern 52
Conclusion 53

5. Table-View-Based Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Simplifying the Template Classes 55
Creating a Table View 58
Organizing and Navigating Your Source Code 61
Connecting the Outlets 62
Building a Model 65
Adding Images to Your Projects 71
Connecting the Controller to the Model 73
Mocking Up Functionality with Alert Windows 74
Adding Navigation Controls to the Application 75
Adding a City View 79
Edit Mode 85
Deleting a City Entry 89
Adding a City Entry 90
The “Add New City...” Interface 93
Capturing the City Data 100

6. Other View Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107


Utility Applications 107
Making the Battery Monitoring Application 108

vi | Table of Contents
Tab Bar Applications 119
Refactoring the Template 120
Adding Another Tab Bar Item 122
Finishing Up 124
Modal View Controllers 125
Modifying the City Guide Application 126
The Image Picker View Controller 133
Adding the Image Picker to the City Guide Application 133

7. Connecting to the Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145


Detecting Network Status 145
Apple’s Reachability Class 145
Embedding a Web Browser in Your App 150
A Simple Web View Controller 150
Displaying Static HTML Files 159
Getting Data Out of a UIWebView 160
Sending Email 161
Getting Data from the Internet 166
Synchronous Requests 166
Asynchronous Requests 167
Using Web Services 168

8. Handling Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191


Data Entry 191
UITextField and Its Delegate 191
UITextView and Its Delegate 193
Parsing XML 195
Parsing XML with libxml2 196
Parsing XML with NSXMLParser 197
Parsing JSON 199
The Twitter Search Service 201
The Twitter Trends Application 202
Regular Expressions 213
Introduction to Regular Expressions 213
Storing Data 217
Using Flat Files 217
Storing Information in an SQL Database 218
Core Data 224

9. Distributing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225


Adding Missing Features 225
Adding an Icon 225
Adding a Launch Image 227

Table of Contents | vii


Changing the Display Name 231
Enabling Rotation 232
Building and Signing 233
Ad Hoc Distribution 233
Developer-to-Developer Distribution 240
App Store Distribution 240
Submitting to the App Store 241
The App Store Resource Center 244
Reasons for Rejection 244

10. Using Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249


Hardware Support 249
Determining Available Hardware Support 249
Setting Required Hardware Capabilities 251
Using the Camera 253
The Core Location Framework 254
Location-Dependent Weather 256
Using the Accelerometer 266
Writing an Accelerometer Application 268
Using the Digital Compass 272
Accessing the Proximity Sensor 274
Using Vibration 275

11. Geolocation and Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277


User Location 277
Annotating Maps 285

12. Integrating Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295


Application Preferences 295
Accessing Global Preferences 305
Custom URL Schemes 305
Using Custom Schemes 305
Registering Custom Schemes 306
Media Playback 310
Using the Address Book 314
Interactive People Picking 315
Programmatic People Picking 319

13. Other Native Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


PhoneGap 321
Download and Installation 322
Building a PhoneGap Project 323
MonoTouch 325

viii | Table of Contents


Download and Installation 325
Building a MonoTouch Project 327

14. Going Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335


Cocoa and Objective-C 335
The iPhone SDK 335
Web Applications 336
Core Data 336
Push Notifications 337
In-App Purchase 338
Core Animation 339
Game Kit 339
Writing Games 339
Look and Feel 340
Hardware Accessories 340

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

Table of Contents | ix
Preface

The arrival of the iPhone changed everything. Or, at the very least, it changed the
direction of software development for mobile platforms, which is a pretty big thing. It
spawned an entire generation of copycat devices and shook an entire multibillion-dollar
industry to its knees. Despite this, it still fits in your pocket.

Who Should Read This Book?


This book gives a rapid introduction to programming for the iPhone and iPod touch
for those with some programming experience. If you are developing on the Mac for the
first time, drawn to the platform because of the iPhone, or alternatively you are an
experienced Mac programmer making the transition to the iPhone, this book is for you.

What Should You Already Know?


The book assumes some knowledge of C, or at least passing knowledge of a C-derived
language. Additionally, while I do give a crash course, some familiarity with object-
oriented programming concepts would be helpful.

What Will You Learn?


This book will guide you through developing your first application for the iPhone, from
opening Xcode for the first time to submitting your application to the App Store. You’ll
learn about Objective-C and the core frameworks needed to develop for the iPhone by
writing applications that use them, giving you a basic framework for building your own
applications independently.

xi
What’s in This Book?
Here’s a short summary of the chapters in this book and what you’ll find inside:
Chapter 1, Why Go Native?
This chapter discusses the need for native applications and compares building
native applications to building web applications.
Chapter 2, Becoming a Developer
This chapter walks you through the process of registering as an iPhone developer
and setting up your work environment, from installing Xcode and the iPhone SDK
to generating the developer certificates you’ll need to build your applications and
deploy them onto your own iPhone or iPod touch.
Chapter 3, Your First iPhone App
This chapter allows you to get hands-on as quickly as possible and walks you
through building your first Hello World application, including how to deploy and
run the application on your iPhone or iPod touch.
Chapter 4, Coding in Objective-C
This chapter provides a crash course in the basics of the Objective-C language, and
if you’re familiar with another C-derived language (and perhaps with object-
oriented programming), it should be enough to get you up and running with
Objective-C and the Cocoa Touch frameworks.
Chapter 5, Table-View-Based Applications
The UITableView and associated classes are perhaps the most commonly used
classes when building user interfaces for iPhone or iPod touch applications. Due
to the nature of the applications, these classes can be used to solve a large cross
section of problems, and as a result they appear almost everywhere. In this chapter,
we dive fairly deeply into the table view classes.
Chapter 6, Other View Controllers
After discussing the table view controller in detail, we discuss some of the other
view controllers and classes that will become useful when building your applica-
tions: simple two-screen views, single-screen tabbed views, modal view controllers,
and a view controller for selecting video and images.
Chapter 7, Connecting to the Network
This chapter discusses connecting to the Internet, browsing the Web, sending
email, and retrieving information.
Chapter 8, Handling Data
This chapter discusses how to handle data input, both from the application user
and programmatically, and how to parse XML and JSON documents. The chapter
also covers storing data in flat files and storing data with the SQLite database
engine.

xii | Preface
Chapter 9, Distributing Your Application
This chapter talks about how to add some final polish to your application and
walks you through the process of building your application for distribution, either
via ad hoc distribution or for the App Store.
Chapter 10, Using Sensors
This chapter discusses how to determine what hardware is available and illustrates
how to deal with the major sensors on the iPhone and iPod touch: the
accelerometer, magnetometer, camera, and GPS.
Chapter 11, Geolocation and Mapping
This chapter walks you through the process of building applications that make use
of the Core Location and MapKit frameworks.
Chapter 12, Integrating Your Application
This chapter shows you some of the tricks to integrate your application with the
iPhone’s software ecosystem, how to present user preferences with Settings Bun-
dles, and how to use custom URL schemes to launch your application. It also
discusses how to make use of the Media Player and Address Book.
Chapter 13, Other Native Platforms
This chapter deals with the PhoneGap and MonoTouch platforms for building
native applications for the iPhone and iPod touch that can be sold on the App Store.
The chapter then walks you through the installation process and building your first
Hello World application for both platforms.
Chapter 14, Going Further
This chapter provides a collection of pointers to more advanced material on the
topics we covered in the book, and material covering some of those topics that we
didn’t manage to talk about in the book.

Conventions Used in This Book


The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions
Constant width
Used for program listings, as well as within paragraphs to refer to program elements
such as variable or function names, databases, data types, environment variables,
statements, and keywords
Constant width bold
Shows commands or other text that should be typed literally by the user
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter-
mined by context

Preface | xiii
This icon signifies a tip, suggestion, or general note.

This icon signifies a warning or caution.

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 iPhone Programming, by Alasdair
Allan. Copyright 2010 Alasdair Allan, 978-0-596-80643-9.”
If you feel your use of code examples falls outside fair use or the permission given here,
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://oreilly.com/catalog/9780596806439
Supplementary materials are also available at:
http://www.learningiphoneprogramming.com/

xiv | Preface
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

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.
With a subscription, you can read any page and watch any video from our library online.
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
Books do not write themselves, but a book is also not the work of just a single person,
despite what it may say on the front cover. I’d like to thank my editor, Brian Jepson.
His hard work and constant prodding made the book better than it might otherwise
have been. I’d also like to offer more than thanks to my long-suffering wife, Gemma
Hobson. Without her support, encouragement, and willingness to make those small
(and sometimes larger) sacrifices that an author’s spouse has to make, this book
wouldn’t be in your hands today. Thank you. Finally to my son, Alex, who is as yet too
young to do more than chew on the cover, daddy’s home. I can only hope for your sake
that O’Reilly uses tasty paper.

Preface | xv
CHAPTER 1
Why Go Native?

When the iPhone was introduced, there was no native SDK. Apple claimed that one
wasn’t needed and that applications for the device should be built as web applications
using JavaScript, CSS, and HTML. This didn’t go down well with the developer com-
munity; they wanted direct access to the hardware and integration with Apple’s own
applications.
Only a few months after the iPhone’s release, the open source community had accom-
plished something that many thought impossible. Despite Apple locking the device
down, developers had gained access, reverse-engineered the SDK, and gone on to build
a free open source tool chain that allowed them to build native applications for the
device. At one point, it was estimated that more than one-third of the iPhones on the
market had been “jail broken” by their users, allowing them to run these unsanctioned
third-party applications.
This open source development effort is ongoing today, and if you want to know more,
I recommend iPhone Open Application Development, Second Edition by Jonathan
Zdziarski (O’Reilly). However, the book you hold in your hands isn’t about the open
source “hacker” SDK, because in March 2008 Apple publicly changed its mind and
released the first version of the native SDK to a waiting developer community. Whether
this release was in response to this effort, or perhaps because it was (the notoriously
secretive) Apple’s plan all along, we’ll probably never know.

The Pros and Cons


When the native SDK was introduced, a number of people in the industry argued that
it was actually a step backward for developers. They felt that web-based applications,
especially once home screen icons for these applications arrived on the 1.1.3 firmware,
were good enough. By writing code specifically for the iPhone in Objective-C, you were
making it more difficult to port your applications, and porting a web application more
or less consisted of simply restyling it using a new CSS template.

1
It seemed that the users of the applications disagreed. It’s arguable why this is the case,
but it’s very hard to make native-looking web applications that can be reused across
many different platforms, though it is possible. Just as applications on the Mac desktop
that have been ported from Windows tend to stand out like a sore thumb by not quite
working as the user expects, web applications, especially those that are intended to be
used across different platforms, tend to do the same.
If you integrate your application into the iPhone ecosphere, make use of the possibilities
that the phone offers, and optimize your user interface (UI) for the device, the user
experience is much improved. It’s also really hard to write web applications that work
well when you need to design for a smaller screen, implying as it does a simpler UI and
less exposed functionality, without using native controls.

Why Write Native Applications?


The obvious reason to use the native SDK is to do things that you can’t do on the Web.
The first generation of augmented reality applications is a case in point; these needed
close integration with the iPhone’s onboard sensors (e.g., GPS, accelerometer, digital
compass, and camera) and wouldn’t have been possible without that access. Although
the iPhone’s Safari browser supports the new geolocation capabilities HTML 5 pro
vides, this doesn’t alleviate the problem entirely. It’s doubtful that all platform-specific
hardware is going to get the same sort of treatment, so it’s unlikely that you will see the
arrival of augmented reality web applications.

If you are coming from a web development background, you may be


interested in the cross-platform PhoneGap framework. This framework
provides native wrapper classes and allows you to build native applica-
tions in HTML/JavaScript on a range of mobile platforms. One of the
platforms it targets is the iPhone. I talk about PhoneGap, and the other
alternative native development platforms for the iPhone, in Chapter 13.

Sometimes it’s not about doing things that can’t be done; it’s about doing things faster,
and doing client-side error handling. For instance, the Apple iTunes and App Store
applications that are provided with the iPhone are actually web applications wrapped
inside native applications. Just like the iTunes Store on the Mac, the main display you
see is a web page, but the surrounding infrastructure is a native application. This means
that while the application can’t do a lot without an Internet connection, it can at least
start up.
But those are extreme examples. A lot of the applications in the App Store combine
remote data and native interfaces. Without access to the network, some of the UI is
generally disabled. However, native applications can be built to degrade gracefully
when the device’s network connection disappears or if it was never present in the first

2 | Chapter 1: Why Go Native?


place. The user can still use the bits of the application that don’t need a network con-
nection to work.
Sometimes it’s also about what an application doesn’t need. If it doesn’t need a network
connection, the idea that your phone needs to be connected to the network to use it,
sucking extra battery power in the process, is wasteful. Even when it is connected, the
device isn’t always connected to a fast Internet connection. Anything you can do to
minimize the amount of data you need to suck down the data connection will improve
users’ interaction with your application. That means generating your UI locally, and
populating it with data pulled from the Internet.
Network performance will affect the user’s perception of speed; rendering your UI
while a web request is made to populate it allows your application to remain responsive
to user interaction even while it’s waiting for the network. That can only be a good
thing.
I haven’t even mentioned game development yet, and with Apple pitching the iPod
touch as “the funnest iPod ever,” that’s important. You cannot develop the sorts of
games now starting to appear on the App Store using web-based technologies. While
this book covers the basics of how to program for the iPhone or iPod touch, if you
want to delve deeply into game programming on the platform, I recommend iPhone
Game Development by Paul Zirkle and Joe Hogue (O’Reilly).

The Release Cycle


Paul Graham, one of my favorite dispensers of wisdom, argues that the arrival of web-
based software has changed not just the user experience, but the developer experience
as well:
One of the most important changes in this new world is the way you do releases. In the
desktop software business, doing a release is a huge trauma, in which the whole company
sweats and strains to push out a single, giant piece of code. Obvious comparisons suggest
themselves, both to the process and the resulting product.
—From “The Other Road Ahead” by Paul Graham
He is exactly right. Working in the cloud, you rarely make a software release in the old
sense of the word. Despite the benefits, I must admit I actually somewhat miss the “big
push” where, usually with a great deal of trepidation, you roll out a new, improved
version of a piece of software. However, one problem with writing native applications
is that we’ve made a return to the release cycle.
With web-based software you can make incremental releases, fixing bugs when and if
they occur. Native applications are far more like desktop software.
I cover the details of how to submit applications to the App Store in Chapter 10. How-
ever, you should prepare yourself now for some amount of pain. The review process is
notoriously opaque, and it can (and does) take time. Plus, each of your applications

The Release Cycle | 3


must go through it, not just when you initially submit it to the store, but also for each
new version you release. Typically, it can take up to 14 days from submitting your
application for it to be approved (or rejected) by the review team, although it can take
much longer. Based on my experience, although some of my applications have sailed
through the submission process in only a couple of days, I have had applications in the
review process for up to four months before receiving approval.

Build It and They Will Come


Of course, the big advantage, even with today’s crowded App Store, is exposure. If
nobody can find your application, nobody can pay for it, and the Web is a big place.
One big advantage a native application has over a web application is that it’s easier for
potential users to find, and much easier to pay for when they find it. That is, if you can
get people to pay for web applications at all. People don’t impulse-subscribe to a web
service; they impulse-buy from the App Store.
However, don’t assume that if you build it, users will appear. Unless you’re really lucky
and your application goes viral, you still need to market your application. The App
Store may be a lot smaller than the Web, but it’s still a pretty big place.
Marketing your application is like marketing any product; you need to make use of the
tools available and your contacts to get news of your software to your target market.
Apple provides promotional codes for your application (although at the time of this
writing, these work only on the U.S. App Store) that will give free downloads of your
applications. Many developers reach out to high-profile blogs or the many application
catalog sites and offer them review copies in hopes that they will publicize the appli-
cation. If it’s well designed and useful, they might well be interested in reviewing it.
Produce a screencast showing how your application works and how to use it. Also,
applications with good support resources (such as forums and trouble-ticket systems)
sell more copies. Applications with good design stand out in the store and sell more
copies.
Good design often means that you do things “the Apple way.” Integrate your applica-
tion well with the other applications on the phone. Don’t reinvent the wheel: use the
standard widgets and UI elements familiar to iPhone users.

4 | Chapter 1: Why Go Native?


CHAPTER 2
Becoming a Developer

Before you start writing code, you need to do some housekeeping. First, you’ll need to
install Xcode, Apple’s development environment, as well as the iPhone SDK. Both of
these are available directly from Apple, although you may already have Xcode on your
Mac OS X install DVD. However, before you can install the iPhone SDK, you’ll have
to register with Apple as a developer. If you enroll in one of the developer programs,
you’ll also need to create, download, and install a number of certificates and profiles
to allow you to deploy your applications onto your iPhone or iPod touch. Let’s get these
housekeeping tasks out of the way now so that you can get to the interesting bit—the
code—as quickly as you can.

Developing applications for the iPhone requires an Intel Mac running


Mac OS X 10.5 (Leopard) or later.

Registering As an iPhone Developer


Before you can develop for the iPhone, you need to become a registered iPhone devel-
oper so that you can download and install the iPhone SDK. This will give you access
to the SDK and allow you to build and test your applications in iPhone Simulator.
If you take it a step further and enroll in the iPhone Developer Standard or Enterprise
Program (both of these have a yearly fee), you’ll be able to test applications on your
own iPhone or iPod touch. We will discuss how to enroll in these programs in the next
section.
If you choose the free account, you won’t be able to install your applications onto your
own iPhone or iPod touch, nor will you be able to sell applications on Apple’s App
Store (Standard Program) or distribute them to people within your own company
(Enterprise Program). If you stick with a free account, you also won’t have access to
prerelease versions of the iPhone SDK or the iPhone OS.
You can sign up at http://developer.apple.com/iphone/.

5
If you are an existing Apple Developer Connection (ADC) member, or
if you have an iTunes or MobileMe account, you can use your existing
Apple ID to register as an iPhone developer. However, if you intend to
sell software commercially, you may want to create a new identity for
use with the program to keep it separate from your existing Apple ID.

You’ll initially be asked to either choose an existing Apple ID or create a new one. If
you create a new one, you’ll be asked for some details (e.g., email and physical ad-
dresses); if you choose an existing Apple ID, you’ll still need to confirm some of these
details, although they should be filled in with the most recent information Apple has.
You’ll also be asked to provide a professional profile, indicating what sort of applica-
tions you’ll be developing and whether you also develop for other mobile platforms.
Finally, you’ll need to agree to the developer license. After you do, a verification code
may be sent to the email address you registered with Apple, although this doesn’t hap-
pen in all cases. However, if this happens to you, the final step of registering as an
iPhone developer will be to verify your email address.

Apple Websites
You’ll use four main websites as part of the iPhone development process:
The iPhone Dev Center
This site is where you can get access to the latest versions of the iPhone SDK, along
with background technical information, API documentation, sample code, and
instructional videos. You need to be a registered iPhone developer to access the site.
The Developer Program Portal
This site is where you can generate and manage the certificates, provisioning pro-
files, approved devices, and other housekeeping tasks necessary to test your ap-
plications on the iPhone and iPod touch and prepare them for distribution. You’ll
need to be both a registered iPhone developer and enrolled in one of the iPhone
Developer Programs to access this site.
The App Store Resource Center
This site provides help and advice on how to distribute your application on the
App Store, including preparing your app for submission, understanding the App
Store approval process, and learning how to manage your apps on the App Store.
You’ll need to be both a registered iPhone developer and enrolled in the iPhone
Developer Standard Program to access this site.
iTunes Connect
This site provides you with the tools to manage your applications on the iTunes
App Store and your contracts with Apple. You’ll need to be both a registered
iPhone developer and enrolled in the iPhone Developer Standard Program to access
this site.

6 | Chapter 2: Becoming a Developer


Enrolling in the iPhone Developer Program
If you intend to sell your applications on the App Store, or you just want to be able to
deploy them onto your own iPhone or iPod touch, you’ll also need to enroll in the
iPhone Developer Program. If you’ve not already registered as an iPhone developer,
you can do that during this process.

Your iPhone Developer Program membership lasts for 1 year and can
be renewed starting 60 days before the expiration date of your existing
membership. If you do not renew your membership, your ability to dis-
tribute your applications will be curtailed. In addition, your developer
and distribution certificates will be revoked. Finally, any applications
you have on the iTunes App Store will be removed.

You have two options when enrolling in the iPhone Developer Program. Most people
will want to register for the Standard Program, which costs $99 per year. This will allow
you to create free—or, once you’ve filled out some paperwork, commercial—
applications for the iPhone and iPod touch, and distribute them either via the App Store
or via the ad hoc distribution channel where you provide both the application binary
and a provisioning certificate to the end user.

Ad hoc distribution allows you to distribute your application directly to


your users, bypassing the App Store. However, distribution is limited
to just 100 devices during the course of your one-year membership and,
at least for the end user, is more complicated than distributing your
application via the App Store. It’s mainly intended for beta testing pro-
grams, and it isn’t a substitute for publishing your application to the
store. If you need to conduct large-scale rollouts to a specific group of
users and you want to avoid the App Store, you should probably look
at the Enterprise Program.

The more expensive Enterprise Program, at $299, is intended for companies with more
than 500 employees that wish to create applications for in-house distribution. While
this program allows you to distribute your applications inside your own company, it
does not allow you to publish them for sale on the App Store. If you’re thinking about
selling your applications to the public, you need the Standard Program.
An iPhone Developer University Program is also available, but this is designed specif-
ically for higher education institutes looking to introduce iPhone development into
their curricula. Unless you’re an academic at such an institute, it’s unlikely that this
program will be applicable to you.

Enrolling in the iPhone Developer Program | 7


Another Random Document on
Scribd Without Any Related Topics
and in places showed his long supple limbs. A shock of black hair
covered his head and shaded his swarthy face. His eyes were wild and
keen as a hawk's, and his tongue hung out of his mouth like a dog's
in a chase. Every man stopped his play and looked at the queer
newcomer. A whisper went round the place that it was that "fule
callant frae Brochtoun," but this brought no news to me.
The man stood still for maybe three minutes with his eyes fixed
on the ground as if to recover breath. Then he got up with dazed
glances, like one wakening from sleep. He stared at me, then at the
players, and burst into his tale, speaking in a high, excited voice.
"I hae run frae Drummeller to bring ye word. Quick and get the
folk out o' the waterside hooses or the feck o' the toun 'll be soomin'
to Berwick in an 'oor."
No one spoke, but all stared as if they took him for a madman.
"There's been an awfu' storm up i' the muirs," he went on,
panting, "and Tweed's com in' doun like a mill-race. The herd o'
Powmood tellt me, and I got twae 'oors start o't and cam off here
what I could rin. Get the folk out o' the waterside hooses when I bid
ye, wi' a' their gear and plenishing, or there'll no be sae muckle as a
groat's worth left by nicht. Up wi' ye and haste, for there's nae time to
lose. I heard the roar o' the water miles off, louder than ony
thunderstorm and mair terrible than an army wi' banners. Quick, ye
auld doited bodies, if ye dinna want to hae mourning and lamentation
i' the toun o' Peebles."
At this, as you may believe, a great change passed over all. Some
made no words about it, but rushed into the town to give the alarm;
others stared stupidly as if waiting for more news; while some were
disposed to treat the whole matter as a hoax. This enraged the
newsbearer beyond telling. Springing up, he pointed to the western
sky, and far off we saw a thick blackness creeping up the skyline. "If
ye'll no believe me," said he, "will ye believe the finger of God?" The
word and the sight convinced the most distrusting.
Now Tweed, unlike all other rivers of my knowledge, rises terribly
at the first rain and travels slowly, so that Tweedsmuir may be under
five feet of water and Peebles high and dry. This makes the whole
valley a place of exceeding danger in sultry weather, for no man
knows when a thunderstorm may break in the hills and send the
stream down a raging torrent. This, too, makes it possible to hear
word of a flood before it comes, and by God's grace to provide
against it.
The green was soon deserted. I rushed down to the waterside
houses, which were in the nearest peril, and in shorter time than it
takes to tell, we had the people out and as much of their belongings
as were worth the saving; then we hastened to the low-lying cottages
on Tweed Green and did likewise. Some of the folk seemed willing to
resist, because, as they said, "Whae kenned but that the body micht
be a leear and they werena to hae a' this wark for naething?" For the
great floods were but a tradition, and only the old men had seen the
ruin which the spate could work. Nevertheless, even these were
convinced by a threatening sky and a few words from the
newsbearer's trenchant tongue. Soon the High Street and the wynds
were thick with household belongings, and the Castle Hill was
crowded with folk to see the coming of the flood.
By this time the grim line of black had grown over half the sky,
and down fell great drops of rain into the white, sun-baked channel. It
was strange to watch these mighty splashes falling into the little
stagnant pools and the runlets of flowing water. And still the close,
thick heat hung over all, and men looked at the dawnings of the
storm with sweat running over their brows. With the rain came a mist
—a white ghastly haze which obliterated the hills and came down nigh
to the stream. A sound, too, grew upon our ears, at first far away and
dim, but increasing till it became a dull hollow thunder, varied with a
strange crackling, swishing noise which made a man eery to listen to.
Then all of a sudden the full blast of the thing came upon us. Men
held their breaths as the wind and rain choked them and drove them
back. It was scarce possible to see far before, but the outlines of the
gorge of Neidpath fleeted through the drift, whence the river issued.
Every man turned his eyes thither and strained them to pierce the
gloom.
Suddenly round the corner of the hill appeared a great yellow
wave crested with white foam and filling the whole space. Down it
came roaring and hissing, mowing the pines by the waterside as a
reaper mows down hay with a scythe. Then with a mighty bound it
broke from the hill-barriers and spread over the haugh. Now, the
sound was like the bubbling of a pot ere it boils. We watched it in
terror and admiration, as it swept on its awful course. In a trice it was
at the cauld, and the cauld disappeared under a whirl of foam; now it
was on the houses, and the walls went in like nutshells and the rubble
was borne onward. A cry got up of "the bridge," and all hung in
wonder as it neared the old stonework, the first barrier to the
torrent's course, the brave bridge of Peebles. It flung itself on it with
fiendish violence, but the stout masonwork stood firm, and the boiling
tide went on through the narrow arches, leaving the bridge standing
unshaken, as it had stood against many a flood. As we looked, we
one and all broke into a cheer in honour of the old masons who had
made so trusty a piece of stone.
I found myself in the crowd of spectators standing next to the
man who had brought the tidings. He had recovered his breath and
was watching the sight with a look half of interest and half of
vexation. When all was past and only the turbid river remained, he
shook himself like a dog and made to elbow his way out. "I maun be
awa'," he said, speaking to himself, "and a sair job I'll hae gettin' ower
Lyne Water." When I heard him I turned round and confronted him.
There was something so pleasing about his face, his keen eyes and
alert head, that I could not forbear from offering him my hand, and
telling him of my admiration for his deed. I was still but a boy and he
was clearly some years my elder, so I made the advance, I doubt not,
with a certain shyness and hesitancy. He looked at me sharply and
smiled.
"Ye're the young laird o' Barns," said he; "I ken ye weel though
ye maybe are no aquaint wi' me. I'm muckle honoured, sir, and gin
ye'll come Brochtoun-ways sometime and speir for Nicol Plenderleith,
he'll tak ye to burns that were never fished afore and hills that never
heard the sound o' a shot."
I thanked him, and watched him slipping through the crowd till
he was lost to view. This was my first meeting with Nicol Plenderleith,
of whose ways and doings this tale shall have much to say. The
glamour of the strange fellow was still upon me as I set myself to
make my road home. I am almost ashamed to tell of my misfortunes;
for after crossing the bridge and riding to Manor Water, I found that
this stream likewise had risen and had not left a bridge in its whole
course. So I had to go up as far as St. Gordians' Cross before I could
win over it, and did not reach Barns till after midnight, where I found
my father half-crazy with concern for me and Tam Todd making ready
to go and seek me.
CHAPTER IV

I GO TO THE COLLEGE AT GLASGOW

By this time I had grown a great stalwart lad, little above the middle
height, but broad and sinewy. I had made progress in all manly sports
and could fling the hammer almost as far as the Manor blacksmith,
while in leaping and running I had few rivals among lads of my age.
Also I was no bad swordsman, but could stand my own against all the
wiles of Tam Todd, and once even disarmed him to his own
unspeakable disgust. In my studies, which I pursued as diligently as I
could with no teachers and not over-many books, I had made some
little advance, having read through most of the Greek tragedians and
advanced some distance in the study of Plato; while in the Latin
tongue I had become such an adept that I could both read and write
it with ease.
When I had reached the mature age of eighteen, who should
come up into our parts but my famous relative, Master Gilbert Burnet,
the preacher at St. Clement's in London, of whom I have already
spoken. He was making a journey to Edinburgh and had turned out of
his way to revive an old acquaintance. My father was overjoyed to see
him and treated him to the best the house could produce. He stayed
with us two days, and I remember him still as he sat in a great
armchair opposite my father, with his broad velvet cap and grey,
peaked beard, and weighty brows. Yet when he willed, though for
ordinary a silent man, he could talk as gaily and wittily as any town
gallant; so much indeed that my father, who was somewhat hard to
please, declared him the best companion he ever remembered.
Before he left, Master Burnet examined me on my progress in
polite learning, and finding me well advanced, he would have it that I
should be sent forthwith to Glasgow College. He exacted a promise
from my father to see to this, and left behind him, when he departed,
letters of introduction to many of the folk there, for he himself had, at
one time, been professor of divinity in the place. As for myself, I was
nothing loth to go, and see places beyond Tweeddale and add to my
stock of learning; for about this time a great enthusiasm for letters
had seized me (which I suppose happens at some time or other to
most men), and I conceived my proper vocation in life to be that of
the scholar. I have found in an old manuscript book a list of the titles
of imaginary works, editions, poems, treatises, all with my unworthy
name subscribed as the author. So it was settled that I should ride to
Glasgow and take lodgings in the town for the sake of the college
classes.
I set out one November morning, riding Maisie alone, for no
student was allowed to have a servant, nor any one below the degree
of Master of Arts. The air was keen and frosty, and I rode in high
fettle by the towns of Biggar and Lanark to the valley of the Clyde. I
lay all night at Crossford in the house of a distant relative. Thence the
next day I rode to Hamilton and in the evening came to the bridge of
the Clyde at Glasgow. Then I presented myself to the Principal and
Regents of the college and was duly admitted, putting on the red
gown, the badge of the student class, than which I believe there is no
more hideous habiliment.
The college in those days was poor enough, having been well-
nigh ruined by the extortions of Lord Middleton and his drunken crew;
and it had not yet benefited by the rich donations of the Reverend
Zachary Boyd of the Barony Kirk. Still, the standard of learning in the
place was extraordinarily high, especially in dialectic and philosophy—
a standard which had been set by the famous Andrew Melville when
he was a professor in the place. I have heard disputations there in the
evenings between the schoolmen and the new philosophers, the like
of which could scarcely be got from the length and breadth of the
land.
Across the High Street were the college gardens and green
pleasant orchards where the professors were wont to walk and the
scholars to have their games. Through the middle ran the clear
Molendinar Burn, so called by the old Romans, and here I loved to
watch the trout and young salmon leaping. There was a severe rule
against scholars fishing in the stream, so I was fain to content myself
with the sight. For soon a violent fit of home-sickness seized me, and
I longed for the rush of Tweed and the pleasant sweep of Manor; so it
was one of my greatest consolations to look at this water and fancy
myself far away from the town. One other lad who came from
Perthshire used to come and stand with me and tell me great tales of
his fishing exploits; and I did likewise with him till we became great
companions. Many afternoons I spent here, sometimes with a book
and sometimes without one; in the fine weather I would lie on the
grass and dream, and in rough, boisterous winter days I loved to
watch the Molendinar, flooded and angry, fling its red waters against
the old stones of the bridge.
No one of us was permitted to carry arms of any kind, so I had to
sell my sword on my first coming to the town. This was a great
hardship to me, for whereas when I carried a weapon I had some
sense of my own importance, now I felt no better than the rest of the
unarmed crowd about me. Yet it was a wise precaution, for in other
places where scholars are allowed to strut like cavaliers there are
fights and duels all the day long, so that the place looks less like an
abode of the Muses than a disorderly tavern. Nevertheless, there were
many manly exercises to be had, for in the greens in the garden we
had trials of skill at archery and golf and many other games of the
kind. At the first mentioned I soon became a great master, for I had a
keen eye from much living among woods and hills, and soon there
was no one who could come near me at the game. As for golf, I
utterly failed to excel; and indeed it seems to me that golf is like the
divine art of poetry, the gift for which is implanted in man at his birth
or not at all. Be that as it may, I never struck a golf-ball fairly in my
life, and I misdoubt I never shall.
As for my studies, for which I came to the place, I think I made
great progress. For after my first fit of home-sickness was over, I fell
in with the ways of the college, and acquired such a vast liking for the
pursuit of learning that I felt more convinced than ever that
Providence had made me for a scholar. In my classes I won the
commendation of both professors; especially in the class of dialectic,
where an analysis of Aristotle's method was highly praised by Master
Sandeman, the professor. This fine scholar and accomplished
gentleman helped me in many ways, and for nigh two months, when
he was sick of the fever, I lectured to his class in his stead. We were
all obliged to talk in the Latin tongue and at first my speech was stiff
and awkward enough, but by and by I fell into the way of it and
learned to patter it as glibly as a Spanish monk.
It may be of interest to those of my house that I should give
some account of my progress in the several studies, to show that our
family is not wholly a soldiering one. In Greek I studied above others
the works of Plato, delighting especially in his Phaedo, which I had
almost by heart; Aristotle likewise, though I read but little of him in
his own tongue. I completed a translation of the first part of Plato's
Republic into Latin, which Master Sandeman was pleased to say was
nigh as elegant as George Buchanan's. Also I was privileged to
discover certain notable emendations in the text of this work, which I
sent in manuscript to the famous Schookius of Groningen, who
incorporated them in his edition then in preparation, but after the
fashion of Dutchmen sent me no thanks.
As regards philosophy, which I hold the most divine of all studies,
I was in my first year a most earnest Platonic; nay, I went farther
than the master himself, as is the way of all little minds when they
seek to comprehend a great one. In those days I went about in sober
attire and strove in all things to order my life according to the rules of
philosophy, seeking to free myself from all disturbing outside powers
and live the life of pure contemplation. I looked back with unutterable
contempt on my past as a turbid and confused medley, nor did I seek
anything better in life than quiet and leisure for thought and study. In
such a condition I spent the first month of my stay at Glasgow.
Then the Platonic fit left me and I was all for Aristotle and the
Peripatetics. Here, at last, thought I, have I got the siccum lumen,
which Heraclitus spoke of: and his distinct and subtle reasoning
seemed to me to be above doubt. And indeed I have never wondered
at the schoolmen and others who looked upon Aristotle as having
reached the height of human wisdom, for his method is so all-
embracing and satisfying that it breeds wonder in the heart of any
man; and it affords so sure a bottom for thought that men become
Aristotelians.
In the midsummer months I went down to Tweeddale again,
where I astonished my father and all in the place with my new
learning, and also grieved them. For I had no love for fishing or
shooting; I would scarce ride two miles for the pleasure of it; my
father's tales, in which I delighted before, had grown tiresome; and I
had no liking for anything save bending over books. When I went to
Dawyck to see Marjory, she knew not what had come over me, I was
so full of whims and fancies. "O John," she said, "your face is as white
as a woman's, and you have such a horrible cloak. Go and get
another at once, you silly boy, and not shame your friends." Yet even
Marjory had little power over me, for I heeded her not, though
aforetime I would have ridden posthaste to Peebles and got me a new
suit, and painted my face if I had thought that thereby I would
pleasure her.
When the autumn came again I returned to college more inclined
than ever for the life of a scholar. I fell to my studies with renewed
zeal, and would doubtless have killed myself with work had I not been
nearly killed with the fever, which made me more careful of my
health. And now, like the weathercock I was, my beliefs shifted yet
again. For studying the schoolmen, who were the great upholders of
Aristotle, I found in them so many contradictions and phantasies
which they fathered on their master that, after reading the diatribes
of Peter Ramus and others against him, I was almost persuaded that I
had been grievously misled. Then, at last, I saw hat the fault lay not
in Aristotle but in his followers, who sought to find in him things that
were beyond the compass of his thought. So by degrees I came round
toward the new philosophy, which a party in the college upheld. They
swore by the great names of Bacon and Galileo and the other natural
philosophers, but I hesitated to follow them, for they seemed to me
to disdain all mental philosophy, which I hold is the greater study. I
was of this way of thinking when I fell in one day with an English
book, a translation of a work by a Frenchman, one Renatus Descartes,
published in London in the year 1649. It gave an account of the
progress in philosophy of this man, who followed no school, but,
clearing his mind of all presuppositions, instituted a method for
himself. This marked for me the turning point; for I gave in my
allegiance without hesitation to this philosopher, and ever since I have
held by his system with some modifications. It is needless for me to
enter further into my philosophy, for I have by me a written exposition
of the works of this Descartes with my own additions, which I intend,
if God so please, to give soon to the world.
For two years I abode at the college, thinking that I was destined
by nature for a studious life, and harbouring thoughts of going to the
university of Saumur to complete my studies. I thought that my spirit
was chastened to a fit degree, and so no doubt it was, for those who
had feared me at first on account of my heavy fist and straightforward
ways, now openly scoffed at me without fear of punishment. Indeed,
one went so far one day as to jostle me off the causeway, and I made
no return, but went on as if nothing had happened, deeming it
beneath a wise man to be distracted by mundane trifles. Yet, mind
you, in all this there was nothing Christian or like unto the meekness
of our Master, as I have seen in some men; but rather an absurd
attempt to imitate those who would have lived very differently had
their lot been cast in our hot and turbid days.
How all this was changed and I veered round of a sudden to the
opposite I must hasten to tell. One April day, towards the close of my
second year, I was going up the High Street toward the Cathedral with
a great parcel of books beneath my arm, when I heard a shouting and
a jingling, and a troop of horse came down the street. I stood back
into the shelter of a doorway, for soldiers were wont to bear little love
to scholars, and I did not care to risk their rough jests. From this
place I watched their progress, and a gallant sight it was. Some
twenty men in buff jerkins and steel headpieces rode with a fine
clatter of bridles and clank of swords. I marked their fierce sun-brown
faces and their daredevil eyes as they looked haughtily down on the
crowd as on lower beings. And especially I marked their leader. He sat
a fine bay horse with ease and grace; his plumed hat set off his high-
coloured face and long brown curls worn in the fashion of the day;
and as he rode he bowed to the people with large condescension. He
was past in a second, but not before I had recognized the face and
figure of my cousin Gilbert.
I stood for some minutes staring before me, while the echoes of
the horses' hooves died away down the street. This, I thought, is the
destiny of my cousin, only two years my elder, a soldier, a gentleman,
a great man in his place; while I am but a nameless scholar, dreaming
away my manhood in the pursuits of a dotard. I was so overwhelmed
with confusion that I stood gaping with a legion of thoughts and
opposing feelings running through my brain. Then all the old fighting
spirit of my house rose within me. By Heaven, I would make an end
of this; I would get me home without delay; I would fling my books
into the Clyde; I would go to the wars; I would be a great cavalier,
and, by the Lord, I would keep up the name of the house! I was
astonished myself at the sudden change in my feelings, for in the
space of some ten minutes a whole age had passed for me, and I had
grown from a boy to some measure of manhood. I came out from the
close-mouth with my head in the air and defiance against all the
world in my eye.
Before I had gone five spaces I met the lad who had jostled me
aforetime, a big fellow of a raw-boned Ayrshire house, and before he
could speak I had him by the arm and had pulled him across the way
into the college gardens. There I found a quiet green place, and
plucking off my coat I said, "Now, Master Dalrymple, you and I have a
small account to settle." With that we fell to with our fists, and in the
space of a quarter of an hour I had beaten him so grievously that he
was fain to cry for mercy. I let him go, and with much whimpering he
slunk away in disgust.
Then I went into the town and bought myself a new blade and a
fine suit of clothes—all with the greatest gusto and lightness of heart.
I went to the inn where Maisie was stabled and bade them have her
ready for me at the college gate in an hour. Then I bade good-bye to
all my friends, but especially to Master Sandeman, from whom I was
loth to part. I did not fling my books into the Clyde as at first I
proposed, but left injunctions that they were to be sent by the carrier.
So, having paid all my debts, for my father had kept me well
appointed with money, I waved a long farewell and set out for my
own country.

CHAPTER V

COUSINLY AFFECTION

It was near midday before I started, so that night I got no farther


than the town of Hamilton, but lay at the inn there. The next morning
I left betimes, thinking to reach Barns in the afternoon. As I rode
along the green sward by the side of Clyde, the larks were singing in
the sky and the trout were plashing in the waters, and all the world
was gay. The apple orchards sent their blossom across the road, and
my hat brushed it down in showers on my horse and myself, so that
soon we rode in a mail of pink and white. I plucked a little branch and
set it in my hat, and sang all the songs I knew as I cantered along. I
cried good-day to every man, and flung money to the little children
who shouted as I passed, so that I believe if there had been many
more boys on the road I would have reached Tweeddale a beggar. At
Crossford, where the Nethan meets the Clyde, I met a man who had
been to the salmon-fishing and had caught a big salmon-trout; and as
I looked, my old love for the sport awoke within me, and I longed to
feel a rod in my hand. It was good to be alive, to taste the fresh air,
to feel the sun and wind, and I cried a plague on all close lecture-
rooms and musty books.
At Lanark I had a rare dinner at the hostel there. The grey old inn
had excellent fare, as I knew of old, so I rode up to the door and
demanded its best. It was blessed to see a man obey your words
after for many months being a servant of others. I had a dish of well-
fed trout and a piece of prime mutton and as good claret, I think, as I
have ever tasted. Then I rode over Lanark Moor to Hyndford and
through the moor of Carmichael and under the great shadow of
Tintock. Here the smell of burning heather came to my nostrils, and
so dear and homelike did it seem that I could have wept for very
pleasure. The whaups and snipe were making a fine to-do on the
bent, and the black-faced sheep grazed in peace. At the top of the
knowe above Symington I halted, for there before my eyes were the
blue hills of Tweeddale. There was Trehenna and the hills above
Broughton, and Drummelzier Law and Glenstivon Dod, and nearer, the
great Caerdon; and beyond all a long blue back which I knew could
be none other than the hill of Scrape which shadowed Dawyck and
my lady.
I came to Barns at three o'clock in the afternoon, somewhat stiff
from my ride, but elated with my home-coming. It was with strange
feelings that I rode up the long avenue of beeches, every one of
which I could have told blindfold. The cattle looked over the palings at
me as if glad to see me return. Maisie cocked up her ears at the hares
in the grass, and sniffed the hill air as if she had been in a prison for
many days. And when I came to the bend of the road and saw the old
weatherbeaten tower, my heart gave a great leap within me, for we
Tweeddale men dearly love our own countryside, doubtless by reason
of its exceeding beauty.
As I rode up Tam Todd came out from the back, and seeing me,
let fall the water which he was carrying and ran to my side.
"Eh, Maister John," said he, "I'm blithe to see ye back, sae braw
and genty-like. My airm's fair like timmer wi' stiffness for want o' the
backsword play, and the troots in Tweed are turned as thick as peas
for want o' you to haul them oot; and twae mornings last week there
were deer keekin' in at the front-door as tame as kittlins. There's
muckle need o' ye at hame."
He would have gone on in this strain for an hour, had I not cut
him short by asking for my father.
"Middlin', just middlin'. He misses ye sair. He'll scarce gang out-
doors noo, but he'll be a' richt gin he sees ye again. Oh, and I've
something mair to tell ye. That wanchancy cousin o' yours, Maister
Gilbert, cam yestreen, and he'll be bidin' till the deil kens when. I'se
warrant he's at meat wi' the auld maister the noo, for he cam in frae
the hills geyan hungry."
Now at this intelligence I was not over-pleased. My cousin was a
great man and a gentleman, but never at any time over-friendly to
me, and I knew that to my father he was like salt in the mouth. I
blamed the ill-luck which had sent him to Barns on the very day of my
home-coming. I needs must be on my dignity in his company, for he
was quick to find matter for laughter, and it was hard that he should
come at the time when I longed so eagerly for the free ways of the
house. However, there was no help for it, I reflected, and went in.
In the passage I met Jean Morran, my old nurse, who had heard
the sound of voices, and come out to see who the newcomer might
be. "Maister John, Maister John, and is't yoursel'? It's a glad day for
the house o' Barns when you come back"; and when I gave her the
shawl-pin I had brought her from Glasgow, she had scarce any words
to thank me with. So, knowing that my father would be in the dining-
hall with his guest, I opened the door and walked in unbidden.
My father sat at the head of the long oak table which had been
scoured to a light-brown and shone like polished stone. Claret, his
favourite drink, was in a tankard by his elbow, and many wines
decked the board. Lower down sat my cousin, gallantly dressed in the
fashion of the times, with a coat of fine Spanish leather and small-
clothes of some rich dark stuff. His plumed hat and riding cloak of
purple velvet lay on the settle at his side. His brown hair fell over his
collar and shoulders and well set off his strong, brown face. He sat
after the fashion of a soldier, on the side of his chair half-turned away
from the table, and every now and then he would cast a piece of
meat to Pierce, my old hound, who lay stretched by the fireplace.
My father turned round as I entered, and when he saw me his
face glowed with pleasure. Had we been alone we should have met
otherwise, but it is not meet to show one's feelings before a stranger,
even though that stranger be one of the family. He contented himself
with looking eagerly upon me and bidding me welcome in a shaking
voice. I marked with grief that his eye did not seem so keen and
brave as before, and that he was scarce able to rise from his chair.
My cousin half arose and made me a grand bow in his courtly
fashion.
"Welcome, my dear cousin," said he. "I am glad to see that your
studies have had little effect on your face." (I was flushed with hard
riding.) "You look as if you had just come from a campaign. But fall to.
Here are prime fish which I can commend; and venison, also good,
though I have had better. Here, too, is wine, and I drink to your
success, my learned cousin"; and he filled his glass and drank it at a
gulp. He spoke in a half-bantering tone, though his words were kindly.
I answered him briskly.
"I had little thought to find you here, Gilbert, but I am right glad
to see you. You are prospering mightily, I hear, and will soon be
forgetting your poor cousins of Barns"; and after a few more words I
set myself to give my father a history of my doings at Glasgow
College. Again, had we been alone, I should have told him my causes
for leaving and my wishes for my after life, but since my cousin was
present, who had ever a sharp tongue, I judged it better to say
nothing.
I told my father all that I could think of, and then asked how he
had fared in my absence, for I had had but few letters, and what of
note had happened at Barns.
"Ay, John," he said, "I'm an old man. I fear that my life here will
be short. I scarce can get outside without Tam Todd to lean on, and I
have little sleep o' nights. And John, I could wish that you would bide
at home now, for I like to see you beside me, and you'll have learned
all the folk of Glasgow have to teach you. I once wished you a soldier,
but I am glad now that I let the thing blow by, for I would have cared
little to have you coming here but once in the six months, for a flying
visit."
"Nay, uncle," said my cousin, "you do not put the matter fairly.
For myself, I believe there is none busier in Scotland than I, but, Gad,
I have always time to slip home to Eaglesham for a day or more. But
my father would care little though he never saw me but once in the
year, for each time I go back I get a long sermon on my conduct, with
my expenses for the year as a text, till I am fairly driven out of the
house for peace."
At this my father laughed. "Ay, ay," said he, "that's like my
brother Gilbert. He was always a hard man at the siller. Man, I mind
when we were both the terrors o' the place, but all the while not a
thing would he do, if it meant the loss of a bodle. Pity but I had taken
after him in that, and John would have been better supplied to-day."
"Oh," I answered, "I have all I need and more."
Hereupon my cousin spoke with a sneer in his voice. "A groat is
enough for a scholar, but the soldier must have a crown. Your scholar,
as doubtless John can tell, is content if he have a sad-coloured suit,
some musty books, and a stoup of bad wine; but your fine gentleman
must have his horses and servants, and dress himself like his quality
for all the maids to stare at, and have plenty of loose silver to fling to
the gaping crowd; and he is a poor fellow indeed if he do not eat and
drink the best that each tavern can give. As for me, I would as soon
be a clown in the fields as a scholar, with apologies to my cousin";
and he made me another of his mocking bows.
I answered as gently as I could that gentrice did not consist in
daintiness of eating and drinking or boisterous display, and that in my
opinion nothing gave so fine a flavour to gentility as a tincture of
letters; but my father changed the conversation by asking Gilbert
what he had been after that day.
"'Faith, it would be hard to say," said he. "I got a gun from that
long-legged, sour-faced groom and went up the big hill above the
trees to have a shot at something. I killed a couple of hares and
sprung an old muirfowl; but the day grew warm and I thought that
the wood would make a pleasant shade, so I e'en turned my steps
there and went to sleep below a great oak, and dreamed that I ran a
man through the bowels for challenging my courage. It was an ill-
omened dream, and I expected to meet with some mishap to account
for it ere I got back, but I saw nothing except a lovely girl plucking
primroses by the water side. Zounds, Jock, what a fool you must be
never to have found out this beauty! She had hair like gold and eyes
like sapphires. I've seen many a good-looking wench, but never one
like her."
"And what did you do?" I asked, with my heart beating wildly.
"Do," he laughed. "Your scholar would have passed in silence and
written odes to her as Venus or Helen for months; whereas I took off
my bonnet and made haste to enter into polite conversation. But this
girl would have none of me; she's a rose, I warrant, with a pretty
setting of thorns. She tripped away, and when I made to follow her,
became Madam Fine-airs at once, and declared that her servants
were within easy reach, so I had better have a care of my conduct."
My father shot a sharp glance at me, and addressed my cousin.
"The maid would be Marjory Veitch, old Sir John's daughter, at
Dawyck. He, poor man, has gone to his account, and her brother is
abroad, so the poor girl is lonely enough in that great house. John
and she have been friends from the time they were children. She has
come here, too, and a pretty, modest lass she is, though she favours
her mother rather than her father's folk."
At this intelligence my cousin whistled long and low. "So, so,"
said he, "my scholar has an eye in his head, has he? And Dawyck is
not far off, and—well, no wonder you do not care for the military
profession. Though, let me tell you, it is as well for the course of true
love that there are few cavaliers in this countryside, else Mistress
Marjory might have higher notions."
I answered nothing, for, though I loved Marjory well, and thought
that she loved me, I had never spoken to her on the matter; for from
childhood we had been comrades and friends. So I did not care to
reply on a matter which I regarded as so delicate and uncertain.
My cousin was a man who grew sorely vexed by receiving no
answer from the object of his wit; and, perhaps on this account, he
went further than he meant in his irritation. "Nay, John," he went on,
"you're but a sorry fellow at the best, with your tags from the Latin,
and your poor spirit. I am one of the meanest of His Majesty's
soldiers, but I can outride you, I can beat you at sword-play, at mark-
shooting, at all manly sports. I can hold my head before the highest in
the land; I can make the vulgar bow before me to the ground. There
are no parts of a gentleman's equipment in which I am not your
better."
Now, had we been alone, I should not have scrupled to fling the
lie in his teeth, and offer to settle the matter on the spot. But I did
not wish to excite my father in his feeble health, so I made no reply
beyond saying that events would show the better man. My father,
however, took it upon himself to defend me. "Peace, Gilbert," he said.
"I will not have my son spoken thus of in my own house. He has as
much spirit as you, I'll warrant, though he is less fond of blowing his
own trumpet." I saw with annoyance that my father plainly thought
my conduct cowardly, and would have been better pleased had I
struck my cousin then and there. But I knew how cruelly excited he
would be by the matter, and, in his weakness, I feared the result.
Also, the man was our guest, and my cousin.
When we rose from supper I assisted my father in walking to his
chair by the fire; for, though the weather was mild and spring-like, his
blood was so impoverished that he felt the cold keenly. Then my
cousin and myself strolled out of doors to the green lawn, below
which Tweed ran low and silvery clear. I felt anger against him, yet
not so much as I would have felt towards another man, had he used
the same words; for I knew Gilbert to be of an absurd boasting
nature, which made him do more evil than he had in his heart. Still
my honour, or pride (call it what you please), was wounded, and I
cast about me for some way to heal it.
"Gilbert," I said, "we have both done much work to-day, so we
are both about equally wearied."
"Maybe," said he.
"But your horse is fresh, and a good one, as I know; and you are
a good horseman, as you say yourself. You had much to say about my
poor horsemanship at supper. Will you try a race with me?"
He looked at me scornfully for a minute. "Nay, there is little
honour to be got from that. You knew the ground, and your horse, for
all I know, may be swifter than mine. It was not of horses I spoke,
but of the riders."
"In the race which I offer you," I answered, "we will both start
fair. Do you see yon rift in the hill beyond Scrape? It is the Red Syke,
a long dark hole in the side of the hill. I have never ridden there, for
the ground is rough and boggy, and I have never heard of a
horseman there since Montrose's rising. Will you dare to ride with me
to yonder place and back?"
At this my cousin's face changed a little, for he had no liking for
breaking his neck on the wild hills. And now, when I look back on the
proposal, it seems a mad, foolhardy one in very truth. But then we
were both young and spirited, and reckless of our lives.
"Mount and ride," said he. "I'll be there and back before you are
half-road, unless, indeed, I have to carry you home."
Together we went round to the stables, and I saddled a black
horse of my father's, for Maisie had already travelled far that day. The
Weasel, we called him, for he was long and thin in the flanks, with a
small head, and a pointed muzzle. He was viciously ill-tempered, and
would allow no groom to saddle him; but before I had gone to
Glasgow I had mounted and ridden him bareback up and down the
channel of Tweed till he was dead-beat, and I half-drowned and
shaken almost to pieces. Ever since this escapade he had allowed me
to do what I liked with him; and, though I did not find him as
pleasant to ride as the incomparable Maisie, yet I knew his great
strength and alertness. My cousin's horse was a good cavalry charger,
strong, but, as I thought, somewhat too heavy in the legs for great
endurance.
We mounted and rode together out among the trees to the fields
which bordered on the hills. I was sore in the back when I started,
but, after the first half-mile, my sprightliness returned, and I felt fit to
ride over Broad Law. My cousin was in an ill mood, for the sport was
not to his taste, though he felt bound in honour to justify his words.
The spur of Scrape, which we came to, was called, by the country
people, the Deid Wife, for there an Irish woman, the wife of one of
Montrose's camp followers, had been killed by the folk of the place
after the rout at Philiphaugh. We had much ado to keep our horses
from slipping back, for the loose stones which covered the face of the
hill gave a feeble foothold. The Weasel took the brae like a deer, but
my cousin's heavy horse laboured and panted sorely before it reached
the top. Before us stretched the long upland moors, boggy, and cleft
with deep ravines, with Scrape on the right, and straight in front, six
miles beyond, the great broad crest of Dollar Law. Here we separated,
my cousin riding forward, while I thought the road to the left would
be the surer. Clear before us lay the Red Syke, an ugly gash, into
which the setting sun was beginning to cast his beams.
And now I found myself in a most perilous position. The Weasel's
feet were light and touchy, and he stumbled among the stones and
tall heather till I had sore work to keep my seat. My cousin's horse
was of a heavier make, and I could see it galloping gallantly over the
broken ground. I cheered my steed with words, and patted his neck,
and kept a tight hand on the rein. Sometimes we slipped among the
shingle, and sometimes stumbled over rocks half-hid in brackens.
Then we passed into a surer place among short, burned heather. The
dry twigs gave forth a strange, creaking sound as the horse's feet trod
on them, and puffs of grey dust and ashes, the sign of the burning,
rose at every step. Then, beyond this, we went to a long stretch of
crisp mountain grass, pleasant for both horse and rider. We splashed
through little tumbling burns, and waded through pools left by the
spring rains. But, of a sudden, the ground grew softer, and even the
Weasel's light weight could not pass in safety. At one time, indeed, I
reined him back just on the brink of a treacherous well-eye, from
which neither of us would have returned. I cast a glance at my
cousin, who was still ahead; his heavy charger was floundering
wearily, and he lashed it as if his life were at stake. Then we passed
the green bog and came to a great peat-moss, full of hags, where the
shepherds had been casting peats. Here the riding was more difficult,
for the holes whence the peats had come were often some five feet
deep, and it was no easy matter to get a horse out of that
treacherous black mud. The Weasel did gallantly, and only once did I
dismount, when his hind feet were too deeply sunk to permit him to
leap. Beyond me I saw my cousin, riding swiftly, for the middle of the
moss, as it chanced, was the firmest and evenest place. We were now
scarce a hundred yards from the ravine of the Red Syke, and, even as
I looked, I saw him reach it, rest a second to give his horse breathing-
space, and then turn on his homeward way.
I came to the place a minute after, and having compassion on my
brave horse, I dismounted, and eased him of my weight for a little.
Then I got on his back again and set off. Gilbert I saw before me,
riding, as I thought, in the worst part, and with a fury that must tell
sooner or later on his heavy steed. I had scarce been a moment in
the saddle, when, so strange are the ways of horses, the Weasel
became aware, for the first time, of the other in front. Before, it had
been a toil for him, now it became a pleasure, a race, which it lay
with his honour to win. He cocked up his wicked, black ears, put
down his head, and I felt the long legs gathering beneath me. I cried
aloud with delight, for now I knew that no horse in Tweeddale could
hope to match him when the mood was on him. He flew over the
hags as if he had been in a paddock; he leaped among the hard parts
of the green bog, from tussock to tussock, as skilfully as if he had
known nothing but mosses all his days. We came up with Gilbert at
the edge of the rough ground, lashing on his horse, with his face
flushed and his teeth set. We passed him like the wind, and were
galloping among the rocks and brackens, while he was painfully
picking his steps. A merciful providence must have watched over the
Weasel's path that day, for never horse ran so recklessly. Among
slippery boulders and cruel jagged rocks and treacherous shingle he
ran like a hare. I grew exultant, laughed, and patted his neck. The
sun was setting behind us, and we rode in a broad patch of yellow
light. In a trice we were on the brow of the Deid Wife. Down we
went, slipping yards at a time, now doubling along the side;
sometimes I was almost over the horse's head, sometimes all but off
the tail; there was never, since the two daft lairds rode down
Horsehope Craig, such a madcap ride. I scarce know how I reached
the foot in safety: but reach it I did, and rode merrily among the trees
till I came to the green meadowlands about the house of Barns. Here
I dismounted and waited for my cousin, for I did not care to have the
serving-men laugh at him riding in after me.
I waited a good half-hour before he appeared. A sorry sight he
presented. His breeches and jerkin had more than one rent in them;
his hat was gone; and his face was flushed almost crimson with effort.
His horse had bleeding knees, and its shoulders shook pitifully.
"Pardon me, Gilbert," I said in a fit of repentance; "it was a
foolish thing in me to lead you such a senseless road. I might have
known that your horse was too heavy for the work. It was no fault of
yours that you did not come home before me. I trust that we may
forget our quarrels, and live in friendship, as kinsmen should."
"Friendship be damned," he cried in a mighty rage.

CHAPTER VI
HOW MASTER GILBERT BURNET PLAYED A GAME
AND WAS CHECKMATED

That night I was too wearied and sore in body to sleep. My mind also
was troubled, for I had made an enemy of my cousin, who, as I knew,
was not of a nature to forgive readily. His words about Marjory had
put me into a ferment of anxiety. Here was my love, bound to me by
no promise, at the mercy of all the gallants of the countryside. Who
was I, to call myself her lover, when, as yet, no word of love had
passed between us? Yet, in my inmost heart, I knew that I might get
the promise any day I chose. Then thoughts of my cousin came to
trouble me. I feared him no more than a fly in matters betwixt man
and man; but might he not take it into his head to make love to the
mistress of Dawyck? and all maids dearly love a dashing cavalier. At
length, after much stormy indecision, I made up my mind. I would
ride to Dawyck next morn and get my lady's word, and so forestall
Gilbert, or any other.
I woke about six o'clock; and, looking out from the narrow
window, for Barns had been built three hundred years before, I saw
that the sky was cloudless and blue, and the morning as clear as
could be seen in spring. I hastily dressed, and, getting some slight
breakfast from Jean Morran, saddled Maisie, who was now as active
as ever, and rode out among the trees. I feared to come to Dawyck
too early, so I forded Tweed below the island, and took the road up
the further bank by Lyne and Stobo. All the world was bright; an early
lark sang high in the heaven; merles and thrushes were making fine
music among the low trees by the river. The haze was lifting off the
great Manor Water hills; the Red Syke, the scene of the last night's
escapade, looked very distant in the morning light; and far beyond all
Dollar Law and the high hills about Manorhead were flushed with
sunlight on their broad foreheads. A great gladness rose in me when I
looked at the hills, for they were the hills of my own country; I knew
every glen and corrie, every water and little burn. Before me the Lyne
Water hills were green as grass with no patch of heather, and to the
left, the mighty form of Scrape, half-clothed in forest, lay quiet and
sunlit. I know of no fairer sight on earth; and this I say, after having
travelled in other countries, and seen something of their wonders; for,
to my mind, there is a grace, a wild loveliness in Tweedside, like a
flower-garden on the edge of a moorland, which is wholly its own.
I crossed Lyne Water by the new bridge, just finished in the year
before, and entered the wood of Dawyck. For this great forest
stretches on both sides of Tweed, though it is greater on the side on
which stands the house. In the place where I rode it was thinner, and
the trees smaller, and, indeed, around the little village of Stobo, there
lies an open part of some fields' width. At the little inn there, I had a
morning's draught of ale, for I was somewhat cold with riding in the
spring air. Then I forded Tweed at a place called the Cow Ford, and,
riding through a wide avenue of lime-trees, came in sight of the grey
towers of Dawyck.
I kept well round to the back, for I did not care that the serving-
folk should see me and spread tales over all the countryside. I knew
that Marjory's window looked sharp down on a patch of green lawn,
bordered by lime-trees, so I rode into the shadow and dismounted. I
whistled thrice in a way which I had, and which Marjory had learned
to know long before, when we were children, and I used to come and
beguile her out for long trampings among the hills. To-day it had no
effect, for the singing of birds drowned my notes, so I had nothing
left but to throw bits of bark against her window. This rude expedient
met with more success than it deserved, for in a minute I saw her
face behind the glass. She smiled gladly when she saw me, and
disappeared, only to appear again in the little door beside the lilacs.
She had no hat, so her bright hair hung loose over her neck and was
blown about by the morning winds. Her cheeks were pink and white,
like apple-blossom, and her lithe form was clad in a dress of blue
velvet, plainly adorned as for a country maiden. A spray of lilac was in
her breast, and she carried a bunch of sweet-smelling stuff in her
hands.
She came gladly towards me, her eyes dancing with pleasure.
"How soon you have returned! And how brave you look," said she,
with many more pretty and undeserved compliments.
"Ay, Marjory," I answered, "I have come back to Tweeddale, for I
have had enough of Glasgow College and books, and I was wearying
for the hills and Tweed and a sight of your face. There are no maidens
who come near to you with all their finery. You are as fair as the
spring lilies in the garden at Barns."
"Oh, John," she laughed, "where did you learn to pay fine
compliments? You will soon be as expert at the trade as any of them.
I met a man yesterday in the woods who spoke like you, though with
a more practised air; but I bade him keep his fine words for his fine
ladies, for they suited ill with the hills and a plain country maid."
At this, I must suppose that my brows grew dark, for she went
on laughingly.
"Nay, you are not jealous? It ill becomes a scholar and a
philosopher as you are, Master John, to think so much of an idle
word. Confess, sir, that you are jealous. Why, you are as bad as a lady
in a play."
I could not make out her mood, which was a new one to me—a
mocking pleasant raillery, which I took for the rightful punishment of
my past follies.
"I am not jealous," I said, "for jealousy is a feeling which needs
an object ere it can exist. No man may be jealous, unless he has
something to be jealous about."
"John, John," she cried, and shook her head prettily, "you are
incorrigible. I had thought you had learned manners in the town, and
behold, you are worse than when you went away. You come here, and
your first word to me is that I am nothing."
"God knows," I said, "I would fain be jealous, and yet—" I
became awkward and nervous, for I felt that my mission was not
prospering, and that I was becoming entangled in a maze of
meaningless speech. The shortest and plainest way is still the best in
love as in all things.
But I was not to be let off, and she finished my sentence for me.
"If only you could find a worthy object for your feeling, you mean,"
she said. "Very well, sir, since I am so little valued in your eyes, we
will speak no more on the matter."
"Marjory," I said, coming to the matter at once, "you and I have
been old comrades. We have fished and walked together, we have
climbed the hills and ridden in the meadows. I have done your
bidding for many years."
"True, John," she said with an accent of grudging reminiscence,
"you have dragged me into many a pretty pickle. I have torn my dress
on rough rocks and soaked my shoes in bogs, all in your company.
Surely we have had a brave time together."
"You met a man in the wood yesterday who would fain have
made love to you. That man was my cousin Gilbert."
"Oh," she replied in a tone of mock solemnity and amused
wonder, for I had blurted out my last words like the last dying
confession of some prisoner. "Verily you are honoured in your
cousinship, John."
"It is against him and such as him that I would protect you," I
said.
"Nay," she cried, with an affected remonstrance. "I will have no
fighting between cousins on my account. I will even defend myself, as
Alison did when the miller made love to her."
"O Marjory," I burst out, "will you not give me this right to defend
you? We have been old companions, but it was only yesterday that I
knew how dearly I loved you. I have had more cares since yester-
night than ever in my life. We have been comrades in childhood; let
us be comrades on the rough paths of the world."
I spoke earnestly, and her face, which had been filled with
mockery, changed gently to something akin to tenderness.
"How little you know of women!" she cried. "I have loved you for
years, thinking of you at all times, and now you come to-day,
speaking as if you had scarce seen me before. Surely I will bear you
company in life, as I have been your comrade at its beginning."
What followed I need scarce tell, since it is but part of the old
comedy of life, which our grandfathers and grandmothers played
before us, and mayhap our grand-children will be playing even now
when our back is turned. Under the spring sky among the lilies we
plighted our troth for the years, and I entered from careless youth
into the dim and resolute region of manhood.
With a great joy in my heart I rode home. I took the high way
over the shoulder of Scrape, for I knew that few folk ever went that
road, and I wished to be alone. The birds were singing, the fresh
clean air was blowing on my face, and the primroses and wind-flowers
made a gay carpet under my horse's feet. All the earth seemed to
partake in my gladness. It was a good world, I thought, full of true
hearts, fair faces, and much good; and though I have seen much
wickedness and sorrow in my day, I am still of the same way of
thinking. It is a brave world; a royal world for brave-hearted men.
When I came to Barns I found that my cousin had gone out an
hour since and left my father greatly wondering at my absence. He
sat in the chair by the fireplace, looking more withered and old than I
had ever seen him. My heart smote me for not staying at his side, and
so I sat down by him and told him many things of my doings in
Glasgow, and how I desired above all things to see the world, having
had my fill of books and colleges. Then I told him what he had long
guessed, of my love for Marjory Veitch and the promise which she had
given me. He heard me in silence, but when he spoke, his words were
cheerful, for he had long liked the lass. He made no refusal, too, to
the rest of my plans. "You shall go and see the world, John," he said,
"and take my blessing with you. It ill becomes a young mettlesome
lad in these stirring times to lounge at home, when he might be
wearing a steel breastplate in the King's Guards, or trying the
manners of twenty nations. Though I could wish you to bide at home,
for I am an old broken man with few pleasures, and I love the sight of
your face."
"Nay, I will never leave you," I said, "an you wish it. I am young
yet and a boy's road is a long road. Time enough for all."
After this I went out to see if the Weasel had come to any mishap
in the last night's ride. I found him as stout as ever, so I saddled him
and rode away by the green haughlands up the valley of the Manor,
for I longed for motion and air to relieve my spirit: and coming home
in the afternoon, I found my cousin returned and sitting with my
father in the dining-hall.
He glanced sharply at me when I entered, and I saw by his looks
that he was in no good temper. His heavy face was flushed and his
shaggy eyebrows were lowered more than their wont.
"Where have you been, Gilbert?" I asked. "I found you gone
when I came back in the morning."
"I took my horse down to Peebles to the farrier. Its knees were
sorely hurt last night on your infernal hills."
Now I knew that this was a lie, for I had looked at his horse
before I went out in the morning, and its wounds were so slight that
it would have been mere folly to take him to a farrier; and Gilbert, I
well knew, was not the man to be in error where horses were
concerned. So I judged that he had ridden in the contrary direction,
and gone to Dawyck, and, as I inferred from his sour looks, met with
no good reception there. I could afford to be generous; I felt a sort of
half-pity for his discomfiture, and forbore to ask him any further
questions.
We sat down to supper, he and I and my father, in a sober frame
of mind. I was full of my own thoughts, which were of the
pleasantest; my cousin was plainly angry with something or other;
and my father, in his weakness dimly perceiving that all was not right,
set himself to mend matters by engaging him in talk.
"You're a good shot with the musket, they tell me, Gibbie," he
said, using the old name which he had called him by when he first
came to Barns as a boy, "and I was thinking that it would be a rare
ploy for you and John to go down the water to Traquair, where
Captain Keith's horse are lying. He is an old friend of mine, and would
be blithe to see any of my kin. They tell me he has great trials of skill
in all exercises, and that he has gathered half the gentry in the place
about him."
"John," said my cousin in a scornful voice, "John is too busily
employed at Dawyck to care much for anything else. A flighty maid is
a sore burden on any man."
"I would have you learn, Master Gilbert," I said angrily, "to speak
in a better way of myself and my friends. You may be a very great
gentleman elsewhere, but you seem to leave your gentility behind
when you come here."
Now my cousin and I were of such opposite natures that I took
most things seriously, while he found matter for a jest in all—yet not
in full good-nature, but with a touch of acrid satire.
"Even a barn-door cock will defend his own roost. How one sees
the truth of proverbs!"
And then he added that which I will not set down, but which
brought my father and myself to our feet with flashing eyes and
quivering lips. I would have spoken, but my father motioned me to be
silent.
"Gilbert," he said, his voice shaking with age and anger, "you will
leave this house the morn. I will have no scoundrelly fellow of your
kidney here. You are no true nephew of mine, and God pity the father
that begat you."
My cousin smiled disdainfully and rose from his chair. "Surely I
will go and at once when my hospitable uncle bids me. The
entertainment in this damned hole is not so good as to keep me long.
As for you, Cousin John," and he eyed me malignantly, "you and I will
meet some day, where there are no dotards and wenches to come
between us. Then I promise you some sport. Till then, farewell. I will
down to Peebles to-night and trouble you no more." With a wave of
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like