0% found this document useful (0 votes)
7 views

Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning instant download

The document provides information on various resources and books related to learning Swift for app development on macOS and iOS. It includes links to download specific titles and highlights the contents of 'Learning Swift 3' by Jon Manning, Paris Buttfield-Addison, and Tim Nugent. The document also outlines the structure of the book, covering Swift basics, app development for OS X and iOS, and extending apps for watchOS.

Uploaded by

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

Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning instant download

The document provides information on various resources and books related to learning Swift for app development on macOS and iOS. It includes links to download specific titles and highlights the contents of 'Learning Swift 3' by Jon Manning, Paris Buttfield-Addison, and Tim Nugent. The document also outlines the structure of the book, covering Swift basics, app development for OS X and iOS, and extending apps for watchOS.

Uploaded by

batyegrocez1
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/ 56

Learning Swift Building Apps for OSX, iOS, and

Beyond Jon Manning pdf download

https://textbookfull.com/product/learning-swift-building-apps-
for-osx-ios-and-beyond-jon-manning/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Learning Swift: Building Apps for macOS, iOS, and


Beyond 2nd Edition Paris Buttfield-Addison

https://textbookfull.com/product/learning-swift-building-apps-
for-macos-ios-and-beyond-2nd-edition-paris-buttfield-addison/

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/

iOS 11 Swift Programming Cookbook Solutions and


Examples for iOS Apps 1st Edition Vandad Nahavandipoor

https://textbookfull.com/product/ios-11-swift-programming-
cookbook-solutions-and-examples-for-ios-apps-1st-edition-vandad-
nahavandipoor/

Swift 4 for Absolute Beginners: Develop Apps for iOS


4th Edition Stefan Kaczmarek

https://textbookfull.com/product/swift-4-for-absolute-beginners-
develop-apps-for-ios-4th-edition-stefan-kaczmarek/
Head First Swift 1st Edition Gray Anthony Manning Jon
Buttfield Addison Paris

https://textbookfull.com/product/head-first-swift-1st-edition-
gray-anthony-manning-jon-buttfield-addison-paris/

Developing Inclusive Mobile Apps: Building Accessible


Apps for iOS and Android 1st Edition Rob Whitaker

https://textbookfull.com/product/developing-inclusive-mobile-
apps-building-accessible-apps-for-ios-and-android-1st-edition-
rob-whitaker/

iOS 10 SDK Development Creating iPhone and iPad Apps


with Swift Chris Adamson

https://textbookfull.com/product/ios-10-sdk-development-creating-
iphone-and-ipad-apps-with-swift-chris-adamson/

iOS Unit Testing by Example XCTest Tips and Techniques


Using Swift 1st Edition Jon Reid

https://textbookfull.com/product/ios-unit-testing-by-example-
xctest-tips-and-techniques-using-swift-1st-edition-jon-reid/

Learn Swift by Building Applications Explore Swift


programming through iOS app development 1st Edition
Emil Atanasov

https://textbookfull.com/product/learn-swift-by-building-
applications-explore-swift-programming-through-ios-app-
development-1st-edition-emil-atanasov/
Learning Swift 3

Jon Manning, Paris Buttfield-Addison, and Tim Nugent

Beijing Boston Farnham Sebastopol Tokyo


Learning Swift 3
by Paris Buttfield-Addison , Jon Manning , and Tim Nugent
Copyright © 2016 Secret Lab. 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://safaribooksonline.com ). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com .

Editor: Rachel Roumeliotis Indexer: FILL IN INDEXER


Production Editor: FILL IN PRODUCTION EDI‐ Interior Designer: David Futato
TOR Cover Designer: Karen Montgomery
Copyeditor: FILL IN COPYEDITOR Illustrator: Rebecca Demarest
Proofreader: FILL IN PROOFREADER

January -4712: First Edition

Revision History for the First Edition


2016-12-05: First Early Release

See http://oreilly.com/catalog/errata.csp?isbn=9781491966990 for release details.

The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning Swift 3, the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author(s) have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibil‐
ity for errors or omissions, including without limitation responsibility for damages resulting from the use
of or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.

978-1-491-96699-0
[FILL IN]
Table of Contents

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Part I. Swift Basics


1. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Apple Developer Program 5
Registering for the Apple Developer Program 6
Downloading Xcode 7
Creating Your First Project with Xcode 8
The Xcode Interface 12
Developing a Simple Swift Application 20
Designing the Interface 21
Connecting the Code 22
Using the iOS Simulator 24
Conclusion 26

2. The Basics of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27


The Swift Programming Language 28
Swift 2 Versus Swift 3 30
Playgrounds 31
Comments 32
Variables and Constants 33
Operators 34
Control Flow 35
Loops 36
Switches 37
Types 40

iii
Working with Strings 40
Comparing Strings 41
Searching Strings 42
Optional Types 42
Type Casting 44
Tuples 45
Arrays 46
Dictionaries 48
Enumerations 48
Sets 50
Functions and Closures 51
Using Functions as Variables 54
Closures 56
The defer Keyword 58
The guard Keyword 58
Making your code Swifty 59
Conclusion 59

3. Swift for Object-Oriented App Development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61


Classes and Objects 61
Initialization and Deinitialization 63
Properties 64
Inheritance 64
Protocols 68
Extensions 69
Access Control 70
Operator Overloading 72
Generics 73
Subscripts 74
Structures 75
Modules 76
The Swift Standard Library, Foundation, Cocoa, and Cocoa Touch 76
Swift Package Manager 77
Data 79
Loading Data from Files and URLs 79
Serialization and Deserialization 80
Error Handling 81
Memory Management 84
Design Patterns in Cocoa and Cocoa Touch 85
Model-View-Controller 85
Delegation 87
Structuring an App 89

iv | Table of Contents
The Application Delegate 89
Window Controllers and View Controllers 89
Nibs and Storyboards 90
Conclusion 90

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

Part II. An OS X App


4. Setting Up the OS X Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Designing the OS X Notes App 124
Creating the OS X Project 127
Defining a Document Type 132
Adding the Icon 136
Conclusion 138

5. Working with Documents on OS X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139


The NSDocument Class 139
Storing Data in the Document 140
Storing Text 141
Package File Formats 142
The guard Keyword, and Why It’s Great 147
Saving Files 148
Loading Files 151
A Basic UI 154
Conclusion 162

6. User Interfaces and iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163


Updating the UI 163
Document-Filetype-Extension UI 167
Getting an Icon for the Collection View Cells 172
Adding Attachments 174
Storing and Managing Attachments 182
Displaying Data in the Collection View 190
Enhancing Attachments 193
Opening Attachments 193
JSON Attachments 197
Adding Attachments via Drag-and-Drop 202
Adding QuickLook 207
iCloud 213
The Basics of iCloud 214

Table of Contents | v
Conclusion 217

Part III. An iOS App


7. Setting Up the iOS Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Designing the iOS Notes App 222
Creating the iOS Project 228
Enabling the iOS App for iCloud 232
Defining a Document Type 236
Conclusion 238

8. Working with Files in iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239


The App Sandbox 239
iCloud Availability 241
Creating the Document List View Controller 242
View Controllers and Storyboards 244
The Navigation Controller 244
Collection Views 248
Using Constraints to Control Size and Position 250
Creating the Document Class 254
Listing Documents 260
Creating Documents 270
Downloading from iCloud 272
Deleting Documents 276
Renaming Documents 283
Conclusion 286

9. Working with Documents on iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289


Adding a View to Display Notes 289
Editing and Saving Documents 297
Conclusion 299

10. Working with Files and File Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301


Setting Up the Interface for Attachments 301
Listing Attachments 305
Determining Types of Attachments 307
Displaying Attachment Cells 310
Dealing with Conflicts 316
Creating the Quick Look Thumbnail 322
Conclusion 325

vi | Table of Contents
11. Images and Deletion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Adding Attachments 327
Adding Image Attachments 329
Viewing Attachments 335
Deleting Attachments 346
Conclusion 353

12. Supporting the iOS Ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355


Sharing with UIActivityController 355
Handoffs 358
Searchability 363
Conclusion 365

13. Extending iOS Apps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367


Searching with a Spotlight Indexing Extension 368
Conclusion 378

14. Multimedia and Location attachments]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379


Audio Attachments 379
Video Attachments 392
Location Attachment 400
Conclusion 404

15. Polishing the iOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405


Opening Links in SFSafariViewController 405
3D Touch 409
Home Screen Quick Actions 410
Peek and Pop 413
Settings 414
Undo Support 416
Images with Filters 419
Worldwide Apps 423
Internationalization 424
Localization 427
Accessibility 432
Splitscreen Multitasking 437
Conclusion 438

Table of Contents | vii


Part IV. Extending Your Apps
16. Building a watchOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Designing for the Watch 442
Designing Our watchOS App 444
Creating the watchOS Extension 446
Communicating with the iPhone 450
User Interfaces for the Apple Watch 469
Showing Note Contents 475
Creating New Notes 482
Adding Handoff Between the Watch and the iPhone 485
Glances 490
Conclusion 494

17. Code Quality and Distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495


Debugging 495
Instruments 498
Testing 503
Unit Testing 504
UI Testing 506
Using Objective-C and Swift in the Same Project 508
Using Swift Objects in Objective-C 508
Using Objective-C Objects in Swift 509
The App Store 510
App Thinning 511
Testing iOS Apps with TestFlight 512
Conclusion 513

viii | Table of Contents


Preface

Welcome to Learning Swift 3! This book will help you put the Swift programming
language into practice by walking you through the development of a note-taking
application for the Apple iOS, OS X, and watchOS platforms.
Swift is a pretty amazing modern language, taking the best from other newer lan‐
guages without reinventing the wheel. Swift is easy to write, easy to read, and really
hard to make mistakes in.
Our philosophy is that the best way to learn Swift is to build apps using it! To build
apps, though, you need a great framework, and Apple has several: Cocoa, Cocoa
Touch, and WatchKit, to name only a few. This book could quite easily be titled
Learning Cocoa and Cocoa Touch with Swift, or something similar, because the frame‐
works are just as important as the language itself. At the time of writing, Swift is cur‐
rently at version 3, and has a bright future ahead of it.

Resources Used in This Book


We recommend following the book by writing code yourself as you progress through
each chapter. If you get stuck, or just want to archive a copy of the code, you can find
what you need via our website.
As this book teaches you how to build a real-world app, we primarily focus on show‐
ing you the coding side of things. We’re not going to ask you to paint your own icons,
so we’ve provided them for you. You can also download them from our website.

Audience and Approach


This book is solely focused on Swift 3 and does not cover the use of Objective-C. We
might mention it occasionally, but we don’t expect you to know how to use it. We first
cover the basics of the Swift 3 language, and then move on to teach as much of the
language as we can, as well as the use of the Cocoa, Cocoa Touch, and watchOS

ix
frameworks, through the construction of a complete app for both OS X and iOS. As a
reminder, Swift is the programming language, Cocoa is the framework for OS X apps,
Cocoa Touch is the framework for iOS apps, and somewhat predictably, watchOS is
the framework for the Apple Watch.
This book’s approach differs from that of other programming books that you may
have encountered. As we’ve mentioned, we believe that the best way to learn Swift is
to build apps using it. We assume that you’re a reasonably capable programmer, but
we don’t assume you’ve ever developed for iOS or OS X, or used Swift or Objective-C
before. We also assume that you’re fairly comfortable navigating OS X and iOS as a
user.

Organization of This Book


In this book, we’ll be talking about Cocoa and Cocoa Touch, the frameworks used on
OS X and iOS, respectively. Along the way, we’ll also be covering Swift, including its
syntax and features.
In Part I, Swift Basics, we begin with a look at the tools used for programming with
Swift, as well as the Apple Developer Program. Then we move on to the basics of the
Swift programming language and structuring a program for Apple’s platforms, as well
as common design patterns.
Chapter 1 covers the basics of Apple’s developer program, and guides you through a
simple Swift app.
Chapter 2 explores all the basics of Swift, and prepares you for using it to build more
complex applications.
Chapter 3 discusses Swift’s object-oriented features, as well as the structure of a good
app.
In Part II, An OS X App, we build a simple note-taking application for Macs, target‐
ing OS X. Along the way, we discuss the design of the app, how it’s structured, how it
uses documents, and how to build all the features.
Chapter 4 starts off our OS X notes app, and sets up the document model, and icon.
Chapter 5 goes into detail on working with documents in OS X apps.
Chapter 6 connects the app to iCloud, and finishes up the OS X app.
In Part III, An iOS App, we build a fully featured iOS note-taking application as a
companion for the OS X app from Part II.
Chapter 7 starts off our iOS app, and sets up the same document model for iOS.
Chapter 8 connects the iOS app to iCloud.

x | Preface
Chapter 9 creates an interface on iOS for displaying our notes.
Chapter 10 sets up the iOS app to handle attachments.
Chapter 11 adds image support to the iOS app.
Chapter 12 adds sharing and searching support to the iOS app.
Chapter 13 adds a today widget to the iOS app.
Chapter 14 adds location, audio, video, and contact attachments to the iOS app, as
well as notifications.
Chapter 15 finishes the iOS app with a whole lot of polish!
In Part IV, Extending Your Apps, we add a watchOS app, and explore bug hunting
and performance tuning.
Chapter 16 adds a watchOS app to the iOS app, allowing for Apple Watch support.
Chapter 17 explores debugging and performance tuning.

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 ele‐
ments 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.

This element signifies a tip or suggestion.

Preface | xi
This element signifies a general note.

This element indicates a warning or caution.

Using Code Examples


Supplemental material (code examples, exercises, errata, etc.) is available for down‐
load at our website.
This book is here to help you get your job done. In general, if example code is offered
with this book, you may use it 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 signifi‐
cant 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 Swift by Jonathon Man‐
ning, Paris Buttfield-Addison, and Tim Nugent (O’Reilly). Copyright 2016 Secret Lab,
978-1-491-94074-7.”
If you feel your use of code examples falls outside fair use or the permission given
above, feel free to contact us at permissions@oreilly.com.

Safari® Books Online


Safari Books Online is an on-demand digital library that deliv‐
ers expert content in both book and video form from the
world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and crea‐
tive professionals use Safari Books Online as their primary resource for research,
problem solving, learning, and certification training.

xii | Preface
Safari Books Online offers a range of plans and pricing for enterprise, government,
education, and individuals.
Members have access to thousands of books, training videos, and prepublication
manuscripts in one fully searchable database from publishers like O’Reilly Media,
Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que,
Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐
mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders,
McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more
information about Safari Books Online, please visit us online.

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://bit.ly/learning-swift.
To comment or ask technical questions about this book, send email to bookques‐
tions@oreilly.com.
For more information about our books, courses, conferences, and news, see our web‐
site at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments
Jon thanks his mother, father, and the rest of his crazily extended family for their tre‐
mendous support.
Paris thanks his mother, without whom he wouldn’t be doing anything nearly as
interesting, let alone writing books.
Tim thanks his parents and family for putting up with his rather lackluster approach
to life.

Preface | xiii
We’d all like to thank our editors, Rachel Roumeliotis and Brian MacDonald—their
skill and advice were invaluable to completing the book. Likewise, all the O’Reilly
Media staff we’ve interacted with over the course of writing the book have been the
absolute gurus of their fields.
A huge thank you to Tony Gray and the Apple University Consortium (AUC) for the
monumental boost they gave us and others listed on this page. We wouldn’t be writ‐
ing this book if it weren’t for them. And now you’re writing books, too, Tony—sorry
about that!
Thanks also to Neal Goldstein, who deserves full credit and/or blame for getting us
into the whole book-writing racket.
We’re thankful for the support of the goons at MacLab (who know who they are and
continue to stand watch for Admiral Dolphin’s inevitable apotheosis), as well as pro‐
fessor Christopher Lueg, Dr. Leonie Ellis, and the rest of the staff at the University of
Tasmania for putting up with us. “Apologies” to Mark Pesce. He knows why.
Additional thanks to Rex S., Nic W., Andrew B., Jess L., and Ash J., for a wide variety
of reasons. And very special thanks to Steve Jobs, without whom this book (and many
others like it) would not have reason to exist.
Thanks also to our tech reviewers, with special thanks to Chris Devers and Tony Gray
for their thoroughness and professionalism.
Finally, thank you very much for buying our book—we appreciate it! And if you have
any feedback, please let us know. You can email us at lab@secretlab.com.au and find us
on Twitter @thesecretlab.

xiv | Preface
PART I
Swift Basics
CHAPTER 1
Getting Started

This book is a work-in-progress. We will be releasing regular Early


Release editions, with a final version late in 2016. The book may be
inconsistent, out of date, or incomplete until then. Please let us
know if you have any feedback by emailing learningswift@secret‐
lab.com.au

This book teaches the Swift 3 programming language by exploring the development
of three applications for Apple platforms: OS X, iOS, and watchOS. This book’s
approach might differ from what you’re used to, because our philosophy is that the
best way to learn Swift is to build apps using it! The vast majority of the code in this
book will be part of the apps we’re building—a full note-taking app for OS X, iOS,
and watchOS—rather than individual pieces of sample code. You can see the final
product in Figure 1-1.

3
Figure 1-1. Our finished app, for OS X, iOS, and watchOS

Our app is fully functional, but we do make some deliberate design and feature deci‐
sions along the way to constrain the scope a little (the book is more than 500 pages!).
As we mentioned in the preface, we assume that you’re a reasonably capable pro‐
grammer, but we don’t assume you’ve ever developed for iOS or OS X, or used Swift
or Objective-C before. We also assume that you’re fairly comfortable navigating OS X
and iOS as a user.

We recommend that you work through this book front to back,


building the OS X app, then the iOS app, then the watchOS app,
even if you’re only interested in one of the platforms. By approach‐
ing the book this way, you’ll get the best understanding of what
building a real app with Swift requires.

Programming with Swift, and using the Cocoa and Cocoa Touch frameworks to
develop OS X and iOS apps, respectively, involves using a set of tools developed by
Apple. In this chapter, you’ll learn about these tools, where to get them, how to use
them, how they work together, and what they can do. At the end of this chapter, you’ll
make a very simple Swift application for iOS, before we dive into the details of the
Swift language and Apple’s frameworks in the following two chapters.

4 | Chapter 1: Getting Started


The Apple development tools have a long and storied history. Orig‐
inally a set of standalone application tools for the NeXTSTEP OS,
they were eventually adopted by Apple for use as the official OS X
tools. Later, Apple largely consolidated them into one application,
known as Xcode, though some of the applications (such as Instru‐
ments and the iOS simulator) remain somewhat separate, owing to
their relatively peripheral role in the development process. You’ll
notice the prefix NS on many of the classes you use for Cocoa and
Cocoa Touch development with Swift. This prefix comes from the
NeXTSTEP heritage of many of Apple’s frameworks.

In addition to the development tools, Apple offers developers a paid membership in


its Developer Program, which provides resources and support. The program allows
access to online developer forums and specialized technical support for those interes‐
ted in talking to the framework engineers. If you are just interested in learning Swift
and exploring the development tools, you can do so for free. You will need a paid
membership, however, if you wish to use developer services like iCloud in your apps,
or to distribute anything you build through either the iOS or OS X App Store.

Swift is open source, but this doesn’t really mean much when it
comes to using it to develop apps for OS X, iOS, and watchOS.
There’s an excellent community of people working on the language
that you can find at the Swift website.

With the introduction of Apple’s curated App Stores for OS X, iOS, and watchOS, as
well as emerging Apple platforms like tvOS, the Developer Program has become the
official way for developers to provide their credentials when submitting applications
to Apple—in essence, it is your ticket to selling apps through Apple. In this chapter,
you’ll learn how to sign up for the Apple Developer Program, as well as how to use
Xcode, the development tool used to build apps in Swift.

The Apple Developer Program


The paid Apple Developer Program provides access to beta development tools, beta
operating system releases, and distribution ability through Apple’s App Stores. It also
allows you to use some of the cloud-dependent features of the platforms, such as
iCloud, CloudKit, In-App Purchase, Maps, and App Groups.

We will be using a lot of cloud-dependent features, including Maps


and iCloud, in the apps we build throughout this book. You will
not be able to run these apps if you do not have a paid member‐
ship.

The Apple Developer Program | 5


It isn’t necessary to be a member of the Apple Developer Program if you don’t intend
to submit apps to the App Stores, or don’t need the cloud-dependent features. We
strongly recommend joining, though, if you intend to build apps for any of Apple’s
platforms, as the other benefits are substantial:

• Access to the Apple Developer Forums, which are frequented by Apple engineers
and designed to allow you to ask questions of your fellow developers and the
people who wrote the OS.
• Access to beta versions of the OS before they are released to the public, which
enables you to test your applications on the next version of the OS X, iOS,
watchOS, and tvOS platforms, and make necessary changes ahead of time. You
also receive beta versions of the development tools.
• A digital signing certificate (one for each platform) used to identify you to the
App Stores. Without this, you cannot submit apps to the App Store, making a
membership mandatory for anyone who wants to release software either for free
or for sale via an App Store.

That said, registering for the Developer Program isn’t necessary to view the docu‐
mentation or to download the current version of the developer tools, so you can play
around with writing apps without opening your wallet.

Registering for the Apple Developer Program


To register for the Developer Program, you’ll first need an Apple ID. It’s quite likely
that you already have one, as the majority of Apple’s online services require one to
identify you. If you’ve ever used iCloud, the iTunes store (for music or apps), or
Apple’s support and repair service, you already have an ID. You might even have
more than one (one of this book’s authors has four). If you don’t yet have an ID, you’ll
create one as part of the registration process. When you register for the Developer
Program, the membership gets added to your Apple ID.

If you don’t want to register for the paid developer program, you
can skip to “Downloading Xcode” on page 7 for instructions on
installing Xcode, the developer tools.
Once again, keep in mind that you won’t be able to build the apps
that we teach in this book if you don’t have a paid membership, as
we use cloud-dependent features such as iCloud and Maps.
There are alternatives to many of Apple’s tools—such as the Google
Maps SDK for iOS, or cloud-storage services from Amazon and
Microsoft. However, you’ll still need a paid membership through
Apple to put apps in the iTunes App Store.

6 | Chapter 1: Getting Started


Once you’re on the Apple Developer Program website, simply click Enroll, and follow
the steps to enroll.
You can choose to register as an individual or as a company. If you register as an indi‐
vidual, your apps will be sold under your name. If you register as a company, your
apps will be sold under your company’s legal name. Choose carefully, as it’s very diffi‐
cult to convince Apple to change your program’s type.
If you’re registering as an individual, you’ll just need your credit card. If you’re regis‐
tering as a company, you’ll need your credit card as well as documentation that
proves you have authority to bind your company to Apple’s terms and conditions.

For information on code signing and using Xcode to test and run
your apps on your own physical devices, see Apple’s App Distribu‐
tion Guide. We don’t cover this in the book, as it’s a process that
changes often.

Apple usually takes about 24 hours to activate an account for individuals, and longer
for companies. Once you’ve received confirmation from Apple, you’ll be emailed a
link to activate your account; when that’s done, you’re a full-fledged developer!

Downloading Xcode
To develop apps for either platform, you’ll use Xcode, Apple’s integrated development
environment. Xcode combines a source code editor, debugger, compiler, profiler, iOS
simulator, Apple Watch simulator, and more into one package. It’s where you’ll spend
the majority of your time when developing applications.

At the time of writing, Xcode is only available for Mac, but who
knows what the future holds for the iPad Pro?

You can get Xcode from the Mac App Store. Simply open the App Store application
and search for “Xcode,” and it’ll pop up. It’s a free download, though it’s rather large
(several gigabytes at the time of writing).
Once you’ve downloaded Xcode, it’s straightforward enough to install it. The Mac
App Store gives you an application that on first launch sets up everything you need to
use Xcode. Just launch the downloaded app, and follow the prompts, and you’ll be up
and running in no time.

The Apple Developer Program | 7


This book covers Swift 3, which is available only if you’re using
Xcode 7 or later. Make sure you’re using the latest version of Xcode
from the Mac App Store. It’s good practice to use the latest Xcode at
all times.

Creating Your First Project with Xcode


Xcode is designed around a single window. Each of your projects will have one win‐
dow, which adapts to show what you’re working on.
To start exploring Xcode, you’ll first need to create a project by following these steps:

1. Launch Xcode. You can find it by opening Spotlight (by pressing ⌘-space bar)
and typing Xcode. You can also find it by opening the Finder, going to your hard
drive, and opening the Applications directory. If you had any projects open previ‐
ously, Xcode will open them for you. Otherwise, the Welcome to Xcode screen
appears (see Figure 1-2).

Figure 1-2. The Welcome to Xcode screen

2. Create a new project by clicking “Create a new Xcode project” or go to


File→New→Project.
You’ll be asked what kind of application to create. The template selector is divi‐
ded into two areas. On the lefthand side, you’ll find a collection of application
categories. You can choose to create an iOS, watchOS, or OS X application from
the project templates, which will set up a project directory to get you started.

8 | Chapter 1: Getting Started


Because we’re just poking around Xcode at the moment, it doesn’t really matter
what we select, so choose Application under the iOS header and select Single
View Application. This creates an empty iOS application and displays the project
settings window shown in Figure 1-3.

Figure 1-3. The project settings window

3. Name the application. Enter HelloSwift in the Product Name section.


4. Enter information about the project. Depending on the kind of project template
you select, you’ll be asked to provide different information about how the new
project should be configured.
At a minimum, you’ll be asked for the following information, no matter which
platform and template you choose:
The product’s name
This is the name of the project and is visible to the user. You can change this
later.
Your organization’s name
This is the name of your company or group. It’s not directly used by Xcode,
but new source code files that you create will mention it.

Creating Your First Project with Xcode | 9


Your organization identifier
This is used to generate a bundle ID, a string that looks like a reverse domain
name (e.g., if O’Reilly made an application named MyUsefulApplication, the
bundle ID would be com.oreilly.MyUsefulApplication).

Bundle IDs are the unique identifier for an application,


and are used to identify that app to the system and to the
App Store. Because each bundle ID must be unique, the
same ID can’t be used for more than one application in
either of the iOS or Mac App Stores. That’s why the for‐
mat is based on domain names—if you own the site use‐
fulsoftware.com, all of your bundle IDs would begin with
com.usefulsoftware, and you won’t accidentally use a bun‐
dle ID that someone else is using or wants to use because
nobody else owns the same domain name.

If you don’t have a domain name, enter anything you like, as long as it looks
like a backward domain name (e.g., com.mycompany will work).

If you plan on releasing your app, either to the App Store


or elsewhere, it’s very important to use a company identi‐
fier that matches a domain name you own. The App Store
requires it, and the fact that the operating system uses the
bundle ID that it generates from the company identifier
means that using a domain name that you own eliminates
the possibility of accidentally creating a bundle ID that
conflicts with someone else’s.

If you’re writing an application for the Mac App Store, you’ll also be prompted
for the App Store category (whether it’s a game, an educational app, a social net‐
working app, or something else).
Depending on the template, you may also be asked for other information (e.g.,
the file extension for your documents if you are creating a document-aware
application, such as a Mac app). You’ll also be asked which language you want to
use; because this book is about Swift, you should probably choose Swift! The
additional information needed for this project is covered in the following steps.
5. Make the application run on the iPhone by choosing iPhone from the Devices
drop-down list.

10 | Chapter 1: Getting Started


iOS applications can run on the iPad, iPhone, or both. Appli‐
cations that run on both are called “universal” applications and
run the same binary but have different user interfaces. For this
exercise, just choose iPhone. You should be building universal
iOS apps, in general, and we’ll be doing that when we properly
start on iOS, in Part III.

6. Leave the rest of the settings as shown in Figure 1-4. Click Next to create the
project.

Figure 1-4. The project settings

7. Choose where to save the project. Select a location that suits you. We recommend
putting all your work related to this book (and other Swift programming learning
you might do) in one folder. You might notice a little checkbox for Source Con‐
trol; this creates a source code control repository for your code, giving you a
place where you can save and manage different versions of your code as you cre‐
ate them. While in general this is a good idea to use, for this example project,
make sure this is unchecked.

Once you’ve done this, Xcode will open the project, and you can now start using the
entire Xcode interface, as shown in Figure 1-5.

Creating Your First Project with Xcode | 11


Figure 1-5. The entire Xcode interface

The Xcode Interface


As mentioned, Xcode shows your entire project in a single window, which is divided
into a number of sections. You can open and close each section at will, depending on
what you want to see.
Let’s take a look at each of these sections and examine what they do.

The editor
The Xcode editor (Figure 1-6) is where you’ll be spending most of your time. All
source code editing, interface design, and project configuration take place in this sec‐
tion of the application, which changes depending on which file you have open.
If you’re editing source code, the editor is a text editor, with code completion, syntax
highlighting, and all the usual features that developers have come to expect from an
integrated development environment. If you’re modifying a user interface, the editor
becomes a visual editor, allowing you to drag around the components of your inter‐
face. Other kinds of files have their own specialized editors as well.
When you first create a project, the editor will start by showing the project settings, as
seen in Figure 1-6.

12 | Chapter 1: Getting Started


Figure 1-6. Xcode’s editor, showing the project settings

The editor can also be split into a main editor and an assistant editor through the edi‐
tor selector. The assistant shows files that are related to the file open in the main edi‐
tor. It will continue to show files that have a relationship to whatever is open, even if
you open different files.
For example, if you open an interface file and then open the assistant, the assistant
will, by default, show related code for the interface you’re editing. If you open another
interface file, the assistant will show the code for the newly opened files.
At the top of the editor, you’ll find the jump bar. The jump bar lets you quickly jump
from the content that you’re editing to another piece of related content, such as a file
in the same folder. The jump bar is a fast way to navigate your project.

The toolbar
The Xcode toolbar (Figure 1-7) acts as mission control for the entire interface. It’s the
only part of Xcode that doesn’t significantly change as you develop your applications,
and it serves as the place where you can control what your code is doing.

Figure 1-7. Xcode’s toolbar

From left to right, after the OS X window controls, the toolbar features the following
items:
Run button (Figure 1-8)
Clicking this button instructs Xcode to compile and run the application.

Creating Your First Project with Xcode | 13


Random documents with unrelated
content Scribd suggests to you:
hospital well, though leaning on his staff, and pale and wan, as
if just recovered from illness. I have now only one painful trial.'
"Presuming that she referred to the spiritual state of her son,
I remarked, that parents must feel intense agony of mind, in
prospect of having their children separated from them in the
eternal world.
"'I have not that prospect to distress me. I have three already
in heaven, and I doubt not but the grace of God will ultimately
reach the heart of my prodigal son. I cannot doubt it. It would
be a sin to doubt it. I have felt such a spirit of prayer come
upon me at times, on his behalf, that I have wrestled for his
conversion, as Jacob wrestled with the angel at Peniel; and
though I have heard no voice saying to me, 'It shall be unto
thee even as thou wilt,' yet I have departed from the throne of
grace in peace, and found my faith strengthened with power
from on high. My faith is so strong and so uniform in its
exercise, that it has cast out fear from my heart; and I can
rejoice in prospect of meeting all my children in my Father's
house.'
"During my absence at Lynnbridge her illness continued to
increase, and Jane used frequently to call on her, and take her
some little comforts which her feeble state required. On my
return I took Mr. ——, who was paying us a short visit, to see
her, and she seemed to derive great comfort from his
conversation and sympathy. She now gained a little strength,
and in a day or two felt herself so much better as to be able
again to go about, and on Sabbath actually walked to chapel.
The exertion, however, had been too much for her, and on
calling at her cottage on the Monday forenoon I was grieved to
learn that she had found herself so weak as to be obliged to
return to bed. I left with her a little wine, which I had brought
with me, and called again to see her in the evening. I perceived
that I must now forego all hopes of her recovery, as her
strength was evidently sinking fast. After some conversation
regarding her bodily ailments, she said to me, 'I have been
struggling through deep waters since your last visit, and even
now the swellings of Jordan are rising higher and higher upon
me; and though I have not lost my anchor, I have been tossed
as upon the billows of the great deep. I trust, indeed, all will be
well at last; but I now feel a terror in prospect of death, which I
never felt before. I am now on the verge of eternity. I shall
soon, very soon see God—the final sentence will soon be
uttered; and if I have been deceiving myself and others, what
will be my doom!'
"'But, my dear Mrs. Kent,' I remarked, 'you should look back
on your past life, and think of the sacrifices which you have
made for the cause of the Redeemer, and the numerous
indications of his approbation which you have received.'
"'I dare not look back,' she replied, with great solemnity,
'unless it be to increase the intensity of the anguish which at
times weighs down my soul, for I have been an unprofitable
servant, and am one of the greatest of sinners that ever
indulged a hope of entering into heaven. Look back! no, my
dear. I am obliged to 'lift up mine eyes unto the hills, from
whence cometh my help.'
"Two days after this visit I again called, and found her sitting
up in her bed. On extending her hand, she said with great
animation, 'The storm is over, and now the sun is shining upon
my soul, in his full noon-tide strength. The bitterness of death is
passed; and I have nothing more to suffer, except a few
convulsive struggles, which nature will feel, when the moment
of my departure comes.' Then raising her hands and her eyes to
heaven, she burst forth into a strain of enraptured devotion. I
have preserved a few of her expressions, which were principally
quotations from the Bible, or Watt's Hymns; but it is not in my
power to portray the calm dignity of her countenance, or the
intense fervour of feeling with which she spoke. 'Blessed
Saviour! thou art my Redeemer! Thou hast borne my sins, and
carried my sorrows! Thou hast suffered the just for the unjust,
to bring me to God! Thou art the chief among ten thousand,
and altogether lovely! Thou art the author and finisher of my
faith! To thee do I yield myself, to be redeemed from all evil—to
be sanctified—to be presented faultless before thy Father's glory
with exceeding joy! Yes,

'——every smile of thine,


Does fresh endearmonts bring;'

and fixing her eyes, as though she saw her Lord, she extended
her arms, and said,

'Haste, my Beloved, fetch my soul,


Up to thy bless'd abode,
Fly, for my spirit longs to see
My Saviour and my God.'

"I happened just then to turn my head to the window, when I


saw a soldier walking up the pathway in front of her cottage.
Without thinking what I was saying, I exclaimed, 'Here is your
son, Mrs. Kent, come back to you from the Cape!' Never shall I
forget the scene which followed.
"'My son!—impossible!'
"We heard the latch of the door lifted up, and a deep manly
voice calling 'Mother!' On that word reaching her ear, his mother
sprang up in her bed, and exclaimed, 'It is my son!' but her
feelings were so strongly excited that she had not strength to
restrain them, and before I could return to her assistance, she
fell back, and for some moments we thought her gone. I felt her
pulse, but it had ceased to beat—her eyes were fixed—and
while engaged with her faithful nurse in employing the usual
means to restore suspended animation, the door of her
chamber was opened, and her son entered with a smile on his
countenance, which was soon exchanged for the strong
expressions of filial grief. He saw what was the matter, and
forbore to speak, but stepping gently to her bedside, he kissed
her, and let fall a tear on her face. 'How long has she been ill?'
he inquired; and just as these words were uttered, we saw a
slight motion of her hand, and soon after she began to breathe
softly. On returning to consciousness, her first impulse was to
embrace her long lost child. No words were uttered by them,
but a frequent interchange of the expressions, 'My child!' 'My
mother!' I withdrew to the window while they remained for
many minutes locked in each other's embrace. I then handed
the dying saint a glass of wine, which revived her; and after
reclining on the bosom of her son for some time, giving vent to
her feelings, she became sufficiently composed to converse with
him.
"'O mother, I am sorry to find you in this state; but you will
get well soon, I trust.'
"'Never while I remain in this world, my dear son. But I have
every reason to be thankful. God has always dealt graciously
with me. Even in the midst of the greatest tribulation, He has
enabled me to sing,

'Bless'd is the sorrow, kind the storm,


That drives me nearer home.'

But this last expression of his kindness, in permitting me to see


you before I die, is so unexpected, that it is like a miracle
wrought in answer to prayer.'
"'O mother,' the soldier replied, weeping as he spoke, 'your
prayers have been the means of my salvation, and I am
thankful that your life has been spared till I could come and tell
you of it.'
"She sat and listened with great interest to his account of his
adventures. While in hospital at the Cape he was visited by a
pious missionary, to whose conversation he ascribed his
conversion to God. 'Before I saw him,' he continued, 'I had
many qualms of conscience; and was often terrified at the
thought of death, but never felt that I needed a Saviour till he
spoke to me. His appeals were like an arrow shot through my
soul, and I could get no comfort till I prayed to Jesus Christ.' He
paused to weep, and we wept with him; when he renewed his
narration, and after giving us a detailed account of his recent
preservation during a violent storm on his return to England, we
knelt down, and he commended the soul of his dying mother
into the hands of the Lord Jesus, after which I took my leave.
"Mrs. Kent remained for several days without undergoing any
material change; but on the eighth day after her son's return,
he called at the Elms, and said that his mother was not
expected to live through the day, and wished to see me. I
immediately went, accompanied by my sister Jane. We found
her in a most heavenly frame of mind. After a conversation
which lasted about half an hour, I observed a sudden alteration
in her countenance, which convinced me that the time of her
departure was drawing nigh. She now sat for several minutes in
perfect silence; a death-like stillness pervaded the room, and we
all felt an awe on our spirits that seemed to betoken some great
event. She then raised her head, and first expressed her
gratitude to her nurse for her kind attention; thanked me and
Jane for the few favours we had been enabled to show her; and
then taking the hand of her son, she pressed it to her lips, and
said, 'Yes, thou art a faithful God! and as it hath pleased thee to
bring back my long lost child, and adopt him into thy family, I
will say, 'Now lettest thou thy servant depart in peace, according
to thy word: for mine eyes have seen thy salvation;' then
smiling, she fell back on her pillow, and with one deep sigh her
gentle spirit passed away and left us.
"Thus lived, thus suffered, and thus died, one of the Lord's
'hidden ones,' set apart for himself, to show forth his praise first
here on earth, and now for ever in the celestial world.
"I am happy to say that I can now refer, with some degree of
satisfaction, to dear Emma, in whose welfare I know you take a
deep interest. I speak with caution, yet I think I can say there
are some appearances, which give us reason to hope, that her
afflictions are beginning to yield the peaceable fruits of
righteousness. She is now more frequently alone and with her
Bible; still very reserved on the question of personal piety, but
references and allusions accidentally escape her lips, which
induce me to believe that the Lord is gradually drawing her to
himself. Dear creature! she has passed through a sad ordeal,
but I trust she will yet be enabled to say with David, 'It is good
for me that I have been afflicted.' Pray for her, my dear friend,
and also for your attached
Louisa."
THE CLOSING SCENE OF THE
YOUNG CHRISTIAN'S CAREER.
Miss Holmes, as the reader has already been informed,
had suffered much in her health, by the unfortunate
marriage of her sister Emma; but her visit to Lynnbridge
had contributed greatly to her improvement, and her
parents now fondly hoped that she was in a fair way of
recovery. Shortly after the death of Mrs. Kent, however, she
experienced a return of her former alarming symptoms, and an
eminent physician was consulted, whose opinion, though rather
reservedly given, was not of a very hopeful nature. Conscious herself
of the extreme delicacy of her constitution, and apprehensive that
she had not long to live, she now prudently declined an
advantageous offer of marriage which she had received. Her suitor
was Mr. Alfred Reed, the only son of an intimate friend of her
father's; a young man, about her own age, decidedly pious, and who
was likely to come into the possession of a large fortune. He had
been bred to mercantile pursuits, but eventually decided on entering
the Church. His father opposed his inclination, till, being fully
convinced that he was actuated by proper motives, he cordially gave
his consent. He had passed through his examinations at Cambridge
with great distinction, and was now spending the vacation at home,
preparatory to taking orders. His person, his manners, and his
profession combined to render him an acceptable suitor to Miss
Holmes, who united in her character the varied excellencies which
are necessary to qualify a female to fill the important station of a
clergyman's wife. She was intelligent, amiable, discreet, and zealous
in the cause of religion and benevolence, without the smallest
tincture of ostentatious display. Her sense of duty, however, would
not permit her, in her present state of health, to contract a union
which might speedily be dissolved, and involve her husband in much
perplexity and grief.
By the advice of her medical man, she was induced again to try a
change of air as the best means of arresting the progress of her
disorder. After much deliberation it was decided to go to Dawlish in
Devonshire, both because they had so much enjoyed their former
visits there, and Louisa preferred its retirement to the noise and
gaiety of a more fashionable watering-place. Mr. Reed, who still
continued faithful in his attentions to her, notwithstanding her refusal
of his offer, and still cherished the hope of his proposals being
accepted, on Miss Holmes' restoration to health, was allowed, at his
earnest request, to form one of the party. He accordingly set out
first, to secure a suitable lodging, and it was no small gratification to
the family when they found he had taken the same house which
they had occupied some years before. As they had travelled by easy
stages, and had been favoured with pleasant weather, Miss Holmes
appeared much better on her arrival at Dawlish than when she left
the Elms; and she continued to improve so rapidly, that all began to
anticipate her entire convalescence. Her spirits, which had at times
been deeply depressed, soon rose to the level of her accustomed
cheerfulness; and though the hectic flush occasionally added fresh
beauty to the sweetness of her countenance, yet, as it did not return
so often, nor appear so deeply tinged by the florid hue as formerly, it
did not occasion any alarm. On returning from a lovely walk, as they
passed the little chapel which benevolence raised for the
accommodation of the Christian pilgrim, who thirsts for the pure
water of life, she facetiously remarked, addressing herself to Mr.
Reed, "I presume, Sir, we cannot calculate on your accompanying us
to-morrow to this unadorned house of prayer."
"Why not, Miss Holmes?"
"Of course, Sir, your clerical profession will lead you elsewhere!"
"I am happy to say, that I am not ashamed to go to offer up my
sacrifice of prayer and of praise in any place in which the God of
salvation will condescend to accept it. I prefer the village church to
the village chapel, most certainly; but, as I have no wish to become
a dissenter, I shall conform to the religious customs of the party
during our visit."
"A clergyman in a Dissenting chapel! The last wonder! Of course,
we must all be sworn to secrecy, and keep our pledge, or no bishop
will ordain you."
There is no indisposition under which the human frame labours
that assumes such a deceptive appearance as a consumption. In its
early stages it will often work so insidiously on the constitution, that
its subject is unconscious of its presence; and even, when it has
advanced to a very considerable extent, there are generally those
intervals of vigour and vivacity, that occasion sanguine expectations
of a recovery to be entertained even to the last. And it is during
these seasons, when the animal spirits return with great force—
giving a degree of energy and activity which is regarded as an
unequivocal proof of restored health, that exertions are made by
walking and by visiting, which often accelerate the fatal issue. To
confine to the house the invalid, who longs to breathe the fresh air,
or to keep her out of company, when the pleasures of social
intercourse relieve the spirits from languor, is a task which the
kindness of friendship cannot always perform; and hence she is
often permitted to run the risk of shortening her life by efforts which
exhaust her strength; or by exposures to the keen night air, which
give a fresh impetus to the disease. It was during one of these
intervals of renewed strength that Miss Holmes was induced to pay a
visit to a family, who resided about two miles off; and though her
father proposed to take her in a carriage, she preferred walking. She
reached her friends' house without feeling fatigued; after dinner
enjoyed a ramble in the country; and then, having taken tea,
returned to Dawlish. It was a pleasant evening, but the air was
rather cold; and though she bore the exertions of the day with great
cheerfulness, yet before she got home she began to feel exhausted.
On entering the drawing-room, she threw herself on the sofa, and
said, "I fear I have gone beyond my strength." After resting herself
some time, she retired for the night; but when she awoke in the
morning, instead of rising at her usual hour, she requested to have
her breakfast in bed. At noon she made her appearance amongst the
family, in apparently good spirits; but her mother, who had watched
the progress of her disorder with deep anxiety, felt alarmed on
seeing the hectic flush on her cheek, accompanied by an occasional
cough. Towards the evening the height of her pulse was
considerably increased; the palms of her hands became dry and hot,
and she complained of being chilly. These symptoms excited fresh
alarm; yet, as they came on immediately after the fatigue of a long
day's excursion, her friends flattered themselves that they would go
off when she had taken another night's rest; but in this they were
disappointed. On the following morning they assumed a more
threatening aspect; her cough became more troublesome, the pain
in her side returned, and though she appeared cheerful, yet it was
accompanied by an unusual gravity of look and manner. At length it
was judged expedient to call in a medical man, who prescribed some
medicines that afforded her a little temporary relief. When asked for
his opinion, he said, "I do not despair of her recovery, though she
must be very cautious. She must not exert herself beyond her
strength, nor yet expose herself to the night air." The following
letter, written to her friend Miss Martin, whom the reader will
remember accompanying Miss Holmes to call on Mrs. Kent,[30]
exhibits the state of her mind at this critical period:—

"My dear Mary,—An all-wise Providence has been pleased to


guide my steps once more to Dawlish, where we expect to
spend a few months. In revisiting it again, I naturally advert to
that period of my life when I was living in a state of alienation
from God—devoted to the pleasures and vanities of the world.
Happy should I now be to ramble with you through this
beautiful country, and talk of Him who lived and died for
sinners; but, as that pleasure is denied me, I will converse with
you through a more circuitous medium. You are aware that our
journey here is mainly on my account. On my arrival I grew
much better, and continued for some weeks to improve in my
general health; but a short time ago I caught a severe cold, and
have never been well since. Though my friends still cling to
hope, as the sinking mariner hangs on the broken plank of the
vessel, till the returning wave comes to drive him off, I am now
very apprehensive as to the result. I know that my heavenly
Father can lengthen out the thread of my life, and restore to full
vigorous health the constitution which disease is gradually
wasting away; but I think He is about to remove me. It costs,
indeed, a hard struggle to view with composure the approach of
death at my age, and nothing could reconcile me to it but the
hope of immortality by which I feel animated and sustained. My
Alfred is with me, and his kind attentions often depress me. He
is still anticipating the day when he shall lead me to the altar;
but alas! fond youth, I am marked out as a victim for the grave!
Yes! and though I still feel I love him, yet I must give him up,
and all the prospects which open before me on this side the
tomb, to go and dwell with Him whom unseen I love! But 'thy
will, O my Father, be done!'
"Though I have received the sentence of death, I do not
expect that it will be executed speedily. No! I shall not be taken
till all are prepared to resign me; and till every tie is loosened
which now fastens my affections to 'things seen and temporal.'
This is a kind provision which our heavenly Father usually makes
to afford some alleviation to the sorrow of surviving friends; and
to enable his children to retire from this vale of life, without
retaining any lingering desires for a longer continuance in it.
"I have hitherto concealed from the eyes of others the most
alarming symptoms of my complaint, nor have I yet given them
an intimation of my own opinion; as I do not feel inclined to be
at present the bearer of such heavy tidings. They still try to
amuse me with the visions of futurity, and talk of my marriage
with Alfred, and all its attendant circumstances, as if length of
days was appointed for me: and though I feel conscious that a
few months, unless a miracle of mercy prevent, will change the
theme of social discourse, yet I cannot bring my mind to the
severe trial of attempting to banish these fond hopes and
anticipations from others.
"I am happy to inform you that my dear sister Emma is
become decidedly pious. Her severe afflictions have had a
salutary effect; and now, being purified and softened by their
influence, she exhibits the features of the Christian character in
all their attractive loveliness. Her natural volatility and satirical
humour are now transformed to chastened vivacity and the
sportive sallies of innocent wit.
"I need not say how much I should enjoy your company at
Dawlish, if you could make it convenient to pay us a visit; but as
that is too great an indulgence for me to expect, you will not
refuse me the gratification of hearing from you as soon as
possible. All here join me in kindest love to you, and your Papa
and Mamma, who, I trust, are both enjoying their usual good
health.—I am, yours most affectionately,
Louisa."

To this letter Miss Martin returned the following reply:—

"London, 15th September, 18—.


"My dear Louisa,—I received yours of the 10th, but it is not
possible for me to describe the impressions which it produced
on my mind. I alternately wept tears of sorrow and of joy; and
though that overpowering excitement, which its first reading
produced, has somewhat subsided, yet I feel almost incapable
of replying. And is the wise Disposer of all events about to
remove you from amongst us? And have you, at such a
comparatively early period of the spiritual contest, fought the
good fight of faith, and gained the crown which fadeth not
away? If so, I will say, 'Happy, thrice happy saint!' thou art
highly favoured of the Lord! Yes, you will soon see the King in
his beauty, and mingle your notes of praise with the multitude
around his throne! You will soon partake of the fulness of joy, in
which the spirits of the just made perfect participate!
"But how can we give you up? How can we take this cup of
sorrow without praying that it may pass from us? How can we
offer up the prayer, 'Thy will, O Father, be done on earth, even
as it is done in heaven,' without feeling it quiver on our lips as
we attempt to utter it? I now find that entire resignation to the
Divine will, when those objects are placed in jeopardy on which
our affections are strongly fixed, is an attainment which I have
not yet acquired; and though I doubt not but the grace of Christ
will be found sufficient for its full display, when the day of trial
comes, yet, at the present moment, I am bowed down with so
much heaviness of soul that I cannot give vent to my feelings.
What a contrast do you exhibit! While I am restless, under the
agitations of fear, you are calm, in the anticipations of hope!
While I am praying that you may still be detained amongst us,
to share our joys and our sorrows, you are fluttering on the
wings of eager expectation, ready to say, as you soar away from
us, 'Weep not for me, but weep for yourselves.' Happy spirit!
"Indeed, my dear Louisa, your sweet composure at this awful
crisis—your bright anticipations, viewed in connection with your
attachment to your friends around you, have given me such an
exalted opinion of the efficacy of the Christian faith to sustain
the human spirit on the great occasions of its history, that I am
not so much astonished at your tranquil joy, as I am at my own
timid misgivings; and though I still hope I possess the faith
which is the evidence of things not seen, yet in me it is small,
like the grain of mustard seed, while in you it resembles the
wide-spreading tree, beneath whose branches you rest in safety.
"As you, my dear Louisa, when drawing nearer the closing
scene, may be subjected to the influence of the fears which not
unfrequently disturb the peace of the dying Christian, I have
taken the liberty of sending you an extract from a very
interesting memoir, which I have just read with great pleasure,
and which, with a degree of precision we rarely meet with in
theological works, points out the difference between faith and
hope.
"'This difference,' the writer justly observes, 'is not always
sufficiently attended to; and much presumption on the one
hand, and despondency on the other, have arisen from
confounding them. One person considers himself a believer of
high attainments, because he entertains no doubt of his being
in a state of salvation; and another doubts whether he be a
believer at all, because he cannot persuade himself that his sins
are forgiven. But it is obvious that two distinct and very different
acts of the mind are here confounded and blended together;—
one, which assents to the fact of Jesus Christ being the only and
all-sufficient Saviour of sinners; and which places a reliance on
the atoning sacrifice, for pardon of sin and acceptance with
God, which is the province of faith; and another, which
appropriates to itself the blessings of this salvation, and
confidently expects a future state of felicity, which is the
province of hope. Now, it is clear that these persuasions of the
mind may exist separately from each other; and that one of
them may be very strong, whilst the other has scarcely any
existence at all. St. Paul clearly recognizes this distinction, when
he offers up a prayer for the Romans, that the God of hope
would fill them with all joy and peace in believing. It is here
implied that genuine faith may exist without either joy or peace;
and by addressing his prayer to 'the God of hope,' he remarks
that joy and peace are the fruits of hope, and are distinct
blessings to be superadded to the grace of faith.'
"I regret that it is not in my power to visit you at Dawlish, but
I assure you that I have you in my remembrance, when bowing
before the God and Father of our Lord Jesus Christ; and while I
pray that you may yet be spared to us, I do not forget to pray,
that if you are to be removed, you may be favoured with a
joyful entrance into the everlasting kingdom of our Lord Jesus
Christ. You will present my kind affection to your dear parents,
and your sisters.—Your affectionate friend,
Mary."

The alarming symptoms which immediately followed this return of


Miss Holmes' disorder, suddenly disappeared, and she was once
more restored to comparative health, though it was evident to all her
friends that the vigour of her constitution was greatly impaired. She
was again permitted to resume her rambles, and to breathe the
genial air of Dawlish, which once more enlivened her spirits. As she
now felt able to endure the fatigues of exertion, she was induced to
comply with the wishes of her kind friends in the country, to pay
them another visit. She rode there and back, and cautiously avoided
running any risk, either by too much exertion, or by any exposure to
damps or cold.
On reaching home, she changed her dress, and soon after retired
to rest; but on awakening in the morning, felt a hoarseness,
accompanied by a slight fever. She remained within for several days,
but on the following Sabbath, felt so much better that she ventured
to go to chapel, where she commemorated the death of the
Redeemer. This religious service she afterwards spoke of as one of
the most impressive and the happiest of her life. When adverting to
it, in a letter which she wrote to Mrs. Loader, she observed, "I have
often felt a great degree of solemnity and delight when receiving the
sacramental memorials of the Saviour's death; but last Sabbath, at
chapel, I felt a joy which was unspeakable and full of glory. When
the minister repeated the memorable words, 'This do in
remembrance of me,' I could not refrain from saying, in the
language of Dr. Watts,

'Why was I made to hear his voice,


And enter while there's room;
While thousands make a wretched choice,
And rather starve than come?'
"I think I have more than once alluded, in my free correspondence
with you, to my ceaseless dread of self-deception; and this makes
me hesitate to ascribe to a supernatural operation, the religious
impressions and tendencies of my heart; yet, on this occasion, I
could respond to the following declarations with perfect composure:

''Twas the same love that spread the feast


That sweetly forced me in;
Else I had still refused to taste,
And perished in my sin.'

"Till that morning a gloomy shade always darkened my prospects


of the future; but then the true light shone into me with such a
bright radiance, that I abounded in hope through the power of the
Holy Ghost. I retired from the hallowed service refreshed and
invigorated; and in the evening, when denied the privilege of
returning to the house of prayer, I made a more solemn surrender of
myself to God, than at any former period. What scenes of wonder
opened to my view! The Lord of life and glory expiring on the cross!
The high and lofty One condescending to admit a sinful creature into
his presence! The Saviour making intercession for me! The gay and
the thoughtless may pour contempt on the sublime pleasures of
devotion, and rush for happiness into a world which abounds with
evil; and under the spell of a fatal illusion, may imagine they have
found it. But our joys would be ill exchanged for theirs; and though
it may not be in our power, while encompassed with the infirmities of
our nature, to perpetuate the vivid impressions which we sometimes
receive, yet they serve to demonstrate the superlative value of the
faith which originates them; and may also tend to inspire within our
breast an intense longing for that fulness of joy in which the spirits
of the just made perfect are allowed to participate in the heavenly
world."
A few days after Louisa's visit to the chapel, the symptoms of her
complaint returned with renewed violence. The physician was again
sent for, and on entering the room, she said, with a smile on her
countenance, "I am happy to see you, Sir; but I am now convinced
that my disorder is beyond your power to remove."
"Perhaps not."
"Yes, Sir, it is; God can restore me if he please, but I do not expect
it."
He sat and conversed with her about a quarter of an hour, and
then left her.
"Pray, Sir," said Mrs. Holmes, "what is your opinion?"
"She is very ill, Madam."
"Do you think it is a confirmed consumption?"
"I do. I fear the disease has made great progress."
"Do you think that a longer continuance in the country will prove
beneficial to the dear sufferer?"
"To be candid, Madam, I do not think that it is in the power of
human means to arrest the progress of the disease, though a
judicious course of management may greatly alleviate her
sufferings."
"Do you think, Sir, she can be removed without much
inconvenience to herself?"
"She may, in the course of a few days, when her strength rallies;
but I am clearly of opinion, that if you wait much longer, it will be
impossible to remove her."
This information came as a death-blow to the hopes of all the
family. Mrs. Holmes, with Jane and Emma, sobbed aloud. A more
silent though not less poignant grief marked the countenances of
her father and Mr. Reed. "If she must die," said her father, "she had
better be taken home to die." "My Louisa die! My dear Louisa die!"
said Alfred, clasping his hands in an intensity of anguish, "And must
she die? and must she be taken from me?" At length he became
more composed, when informed by Mrs. Holmes that Louisa had just
awaked out of a sweet sleep, much revived, and wished to see him.
The family sat conversing together the whole of the evening, and
arranged the plan for returning to the Elms, whither they determined
to proceed immediately.
For the space of a fortnight after her return home, Miss Holmes
continued to improve so rapidly in appearance that the hope of life
began to beam once more upon all except herself. At this time she
wrote the following letter to Miss Martin, who had now gone with
her parents to Hastings for a short period:—

"My dear Mary,—A kind Providence has permitted me to see


the Elms once more, and once more to commune with my
absent friend from my own room, a privilege which I could not
have anticipated a few weeks since. After the reception of your
kind letter, my disorder took a turn, and we again thought that
the bitterness of death was passed; but in the midst of our joy
the symptoms reappeared, and I was brought near to the grave.
I have again revived, but it is only to protract my course for a
little time longer. I may live through the winter, and I may live to
see another spring opening with all its beauties, but I do not
expect it. The symptoms of death are upon me. The silver cord
is broken, and my affections are dying off from earth. I am
beginning to feel as a stranger amongst my most endeared
friends and relatives; and though their sorrows excite my
sympathy, yet I have no wish to remain here longer. No! I hear
a voice they do not hear, and see a form of beauty they cannot
see. I long to depart. I can look through my window on the
walks which wind round our shrubbery, without wishing to
retrace my former footsteps. I can muse on the pleasures which
I have enjoyed in the social circle, without desiring to taste
them again. I still feel that I am a sinner—an unworthy sinner;
my perceptions of the evil of sin are more clear and affecting
than at any former period of my life; and at times I am almost
overwhelmed by the indescribable manifestations of the Divine
purity; but it hath pleased God to impart to me corresponding
views of the efficacy of the precious blood of Christ, so that I
have no fears ruffling my peace. I am entering the valley, but it
is not dark: nor do I hear any sounds but those of Mercy's
voice. The enemy has not yet been suffered to stir up his
strength against me, nor have I been once tempted to mistrust
either the fidelity of the Saviour, or his willingness to save me. I
thank you for the extract which you sent me. It defines the
essential difference between faith and hope with great accuracy
and precision; but I have now done with all human
compositions. The only book I now read is the Bible. This is the
fountain from whence I now draw the pure water of life; and
though I feel thankful for the writings of those good men which
have contributed to my spiritual improvement and consolation,
yet, like withered flowers, they have lost their beauty and their
fragrance.
"I do not think that I should have preferred any other period
of my existence for my departure, to the present, even if I had
been permitted to choose. If I had been taken earlier, I should
have left some of my relatives in the gall of bitterness; and if
spared longer, I might have left some hapless children; but now
I can embrace all as fellow-heirs of the grace of life, who are
nearly allied to me by the ties of nature, and I can quit the
world without leaving any chasm which may not soon be closed.
My friends will weep over my grave, but the hope of a re-union
in a better world will mitigate the violence of their sorrow; and
soon the days of their mourning will be ended, and earth will be
exchanged for heaven.
"Farewell, my dear friend; but only for a season. We are soon
to be separated, but we shall meet again. With kind
remembrance to all.—Your dying friend,
"Louisa."
Miss Holmes had now another relapse, which destroyed all hope of
her recovery. Addressing her mother, who was communicating, in a
low voice, to Mr. Reed the opinion of the physician, she said, "You
need not whisper, I have long known that I should not recover; and
now you know it, let us converse together as those who are on the
eve of parting."
"I have long feared it," said Mrs. Holmes, "though I have been
unable to express my fears."
"But why, my dear Mamma, should you fear it? Death has lost its
sting. The grave has lost its gloom. I am merely preceding you, and
preceding you under the most auspicious circumstances."
"Then has my dear Louisa no dread of death?"
"No. I have outlived that dread of dying which once bowed down
my spirits; and can smile on the king of terrors, who now appears
transformed into an angel of deliverance."
"But have you," said Mr. Reed, "no wish to live?"
"I had, Alfred, but now I have not. I once wished to live to share
your sorrows and your joys, and animate you in the discharge of
your sacred duties; but now I wish to depart and be with Christ,
which is far better."
On seeing her mother and sisters weep, she said, "I am not
surprised by your tears, because, if either of you were in my place, I
should weep. I know that nature must give vent to her feelings; but
you cannot expect me to weep. Weep I cannot, unless I shed the
tear of grateful joy. No! My days of weeping are passed away; and
soon my days of suffering will be over."
Though her disease had been for some time making rapid
progress towards the fatal issue, her spirits were yet buoyant, and
occasionally she was as energetic and cheerful as in former days.
One evening, when the family were sitting with her, she talked with
a vivacity and fluency which induced them to hope that she might be
spared to them for some months, if not years longer. While indulging
these expectations, they were aroused from their reverie by the
sudden entrance of Emma, who brought her the following letter,
from her friend Mrs. Loader, which the postman had just delivered:—

"My dear Friend,—The affectionate letter which I have just


received from dear Emma, brings the mournful intelligence of
your relapse, and that now all hope of your recovery has
vanished away. This intelligence, though mournful to others, is
not, I am thankful to hear, a cause of sorrow to yourself. You
are now on Pisgah, with the dreary wilderness behind you; and
the goodly land of promise in view, overshadowed by no
darkening cloud. My sympathies I reserve for others; to you, I
offer my congratulations. The contest is over; the victory is won,
and ere long you will receive the fadeless crown of immortality.
In a few weeks or days, you, who are now an inhabitant of
earth, will be a glorified spirit, beholding the face of the Holy
One, and uniting with the saints in heaven in the grand chorus
of adoration and praise. What you will then feel, on looking back
on the scene through which you are now passing; or how you
will give expression to your thoughts and emotions, is beyond
all power of conjecture; but it is sufficient to be assured that
you will be perfectly happy, and released from all earthly cares
and anxieties. Happy spirit!—happy, because redeemed;—
happy, because brought in safety to the end of your pilgrimage;
—and happy, now that the shadow of death is flitting across
your path—the visible sign of the coming of your Lord, to take
you to himself. Adieu, my much-loved friend, but not for ever;
the hope of a re-union sustains the dying and the living. We
shall weep when you are rejoicing with the spirits of the just
amid the unfading glories of the celestial world.
"The Lord be with you. Again I say adieu, my much-loved
friend; but only for a season. My love and sympathy to all the
dear members of your family.—Ever yours,
E. Loader."
Miss Holmes read this letter, shed a few tears, and then presented
it to Emma, saying, "When the crisis is over, acknowledge for me
receipt of it; and tell Mrs. Loader what pleasure it gave me."
The tide of life was now rapidly ebbing; and on her father entering
her room, a few days after receiving Mrs. Loader's letter, she
stretched forth her hand, and said, "I hope you are prepared to
resign me, for I have not long to be with you."
"I have had," he replied, "a hard struggle to do it; but the Lord
has at length enabled me to say, 'Even so, for so it seemeth good in
thy sight.'"
"I am glad to hear it; and I hope you will all be enabled to feel the
same resignation to the Divine will. I wish you would now pray with
me, that I may be strengthened in my soul to endure the last
struggle." When this hallowed and deeply affecting exercise was
ended, she reclined her head on the pillow, and slept for two hours.
When she awoke, she rose up in her bed, and casting a smile on all
around her, said, "My sleep has refreshed me." After giving a few
directions respecting her funeral, she delivered the keys of her desk,
&c., to her mother, with a request that she would distribute the few
trifling presents she had marked for her friends, and then added,
"Now I have done with earth. Come, Lord Jesus, come quickly!" As
she gave utterance to this prayer, her countenance beamed with an
indescribable glow of rapture, and with a gentle bending of the neck,
she bid all farewell, her lips distinctly articulating, "Precious Saviour!
thou art come," as they were closing in perpetual silence.

The sketch which I have exhibited of Miss Holmes' character and


religious experience, has been taken from real life; and though on
some points her experience may differ from that of the pious reader,
yet that circumstance will not diminish the degree of interest which
may be felt on examining it. We see what human nature is, even
with all the advantages of a pious education, before the great
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!

textbookfull.com

You might also like