100% found this document useful (5 votes)
106 views

iOS 12 Programming Fundamentals With Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg Download PDF

Fundamentals

Uploaded by

julyanrayeez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
106 views

iOS 12 Programming Fundamentals With Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg Download PDF

Fundamentals

Uploaded by

julyanrayeez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Download the full version of the textbook now at textbookfull.

com

iOS 12 Programming Fundamentals with Swift


Swift Xcode and Cocoa Basics 5th Edition Matt
Neuburg

https://textbookfull.com/product/ios-12-
programming-fundamentals-with-swift-swift-xcode-
and-cocoa-basics-5th-edition-matt-neuburg/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

iOS 12 Programming Fundamentals with Swift Swift Xcode and


Cocoa Basics 5th Edition Matt Neuburg

https://textbookfull.com/product/ios-12-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-5th-edition-matt-neuburg-2/

textbookfull.com

iOS 12 Programming Fundamentals with Swift Swift Xcode and


Cocoa Basics 5th Edition Matt Neuburg

https://textbookfull.com/product/ios-12-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-5th-edition-matt-neuburg-3/

textbookfull.com

iOS 10 Programming Fundamentals with Swift Swift Xcode and


Cocoa Basics 3rd Edition Matt Neuburg

https://textbookfull.com/product/ios-10-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-3rd-edition-matt-neuburg/

textbookfull.com

Leveraging Applications of Formal Methods Verification and


Validation Discussion Dissemination Applications 7th
International Symposium ISoLA 2016 Imperial Corfu Greece
October 10 14 2016 Proceedings Part II 1st Edition Tiziana
https://textbookfull.com/product/leveraging-applications-of-formal-
Margaria
methods-verification-and-validation-discussion-dissemination-
applications-7th-international-symposium-isola-2016-imperial-corfu-
greece-october-10-14-2016-proceedings/
textbookfull.com
The Rough Guide to Poland 8th Edition Rough Guides

https://textbookfull.com/product/the-rough-guide-to-poland-8th-
edition-rough-guides/

textbookfull.com

Civil Society 3rd Edition Michael Edwards

https://textbookfull.com/product/civil-society-3rd-edition-michael-
edwards/

textbookfull.com

Norms in the Wild: How to Diagnose, Measure, and Change


Social Norms 1st Edition Cristina Bicchieri

https://textbookfull.com/product/norms-in-the-wild-how-to-diagnose-
measure-and-change-social-norms-1st-edition-cristina-bicchieri/

textbookfull.com

Coding Art: The Four Steps to Creative Programming with


the Processing Language Yu Zhang

https://textbookfull.com/product/coding-art-the-four-steps-to-
creative-programming-with-the-processing-language-yu-zhang/

textbookfull.com

The Negative Thoughts Workbook: CBT Skills to Overcome the


Repetitive Worry, Shame, and Rumination That Drive Anxiety
and Depression David A. Clark
https://textbookfull.com/product/the-negative-thoughts-workbook-cbt-
skills-to-overcome-the-repetitive-worry-shame-and-rumination-that-
drive-anxiety-and-depression-david-a-clark/
textbookfull.com
Advances in Chromatography, Volume 57 1st Edition Nelu
Grinberg (Editor)

https://textbookfull.com/product/advances-in-chromatography-
volume-57-1st-edition-nelu-grinberg-editor/

textbookfull.com
Xc

C o 0,
od

ve a n
e1

rs d
i O Sw
S 1 if t
2, 4
.2
iOS 12
Programming
Fundamentals
with Swift
SWIFT, XCODE, AND COCOA BASICS

Matt Neuburg
FIFTH EDITION

iOS 12 Programming
Fundamentals with Swift
Swift, Xcode, and Cocoa Basics

Matt Neuburg

Boston
iOS 12 Programming Fundamentals with Swift, Fifth Edition
by Matt Neuburg
Copyright © 2018 Matt Neuburg. 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://oreilly.com/safari). For more information, contact our corporate/insti‐
tutional sales department: 800-998-9938 or corporate@oreilly.com.

Editor: Rachel Roumeliotis Cover Designer: Karen Montgomery


Production Editor: Kristen Brown Interior Designer: David Futato
Proofreader: O’Reilly Production Services Illustrator: Matt Neuburg
Indexer: Matt Neuburg

April 2015: First Edition


October 2015: Second Edition
October 2016: Third Edition
October 2017: Fourth Edition
September 2018: Fifth Edition

Revision History for the Fifth Edition


2018-09-26: First release

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

The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. iOS 12 Programming Fundamentals
with Swift, the image of a harp seal, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
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.

ISBN: 978-1-492-04455-0
[LSI]
Table of Contents

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Part I. Language
1. The Architecture of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Ground of Being 3
Everything Is an Object? 5
Three Flavors of Object Type 6
Variables 6
Functions 8
The Structure of a Swift File 9
Scope and Lifetime 11
Object Members 13
Namespaces 13
Modules 14
Instances 15
Why Instances? 17
The Keyword self 19
Privacy 20
Design 22
Object Types and APIs 23
Instance Creation, Scope, and Lifetime 25
Summary and Conclusion 25

2. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Function Parameters and Return Value 27
Void Return Type and Parameters 31
Function Signature 32
External Parameter Names 32

iii
Overloading 34
Default Parameter Values 35
Variadic Parameters 35
Ignored Parameters 36
Modifiable Parameters 37
Function in Function 40
Recursion 42
Function As Value 42
Anonymous Functions 45
Define-and-Call 51
Closures 52
How Closures Improve Code 54
Function Returning Function 55
Closure Setting a Captured Variable 58
Closure Preserving Its Captured Environment 59
Escaping Closures 60
Curried Functions 60
Function References and Selectors 62
Function Reference Scope 64
Selectors 65

3. Variables and Simple Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69


Variable Scope and Lifetime 69
Variable Declaration 71
Computed Initializer 74
Computed Variables 76
Setter Observers 79
Lazy Initialization 80
Built-In Simple Types 82
Bool 82
Numbers 84
String 92
Character and String Index 96
Range 101
Tuple 103
Optional 105

4. Object Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119


Object Type Declarations and Features 119
Initializers 121
Properties 127
Methods 130

iv | Table of Contents
Subscripts 132
Nested Object Types 135
Instance References 135
Enums 137
Raw Values 138
Associated Values 140
Enum Case Iteration 142
Enum Initializers 143
Enum Properties 144
Enum Methods 145
Why Enums? 146
Structs 147
Struct Initializers, Properties, and Methods 147
Struct As Namespace 149
Classes 149
Value Types and Reference Types 150
Subclass and Superclass 156
Class Initializers 161
Class Deinitializer 169
Class Properties and Methods 170
Polymorphism 172
Casting 175
Casting Down 176
Type Testing and Casting Down Safely 176
Type Testing and Casting Optionals 178
Bridging to Objective-C 178
Type References 180
From Instance to Type 180
Type as Value 181
The Keyword Self 183
Comparing Types 184
Summary of Type Terminology 185
Protocols 186
Why Protocols? 187
Protocol Type Testing and Casting 189
Declaring a Protocol 190
Protocol Composition 191
Optional Protocol Members 192
Class Protocol 194
Implicitly Required Initializers 195
Literal Convertibles 196
Generics 197

Table of Contents | v
Generic Declarations 200
Contradictory Resolution 202
Type Constraints 203
Explicit Specialization 205
Generic Invariance 207
Associated Type Chains 208
Where Clauses 210
Extensions 213
Extending Object Types 213
Extending Protocols 215
Extending Generics 217
Umbrella Types 219
Any 219
AnyObject 221
AnyClass 223
Collection Types 224
Array 224
Dictionary 240
Set 247

5. Flow Control and More. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253


Flow Control 253
Branching 254
Loops 266
Jumping 271
Privacy 286
Private and Fileprivate 288
Public and Open 289
Privacy Rules 290
Introspection 290
Operators 291
Synthesized Protocol Implementations 295
Key Paths 298
Dynamic Member Lookup 300
Memory Management 301
Memory Management of Reference Types 301
Exclusive Access to Value Types 308

Part II. IDE

vi | Table of Contents
6. Anatomy of an Xcode Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
New Project 313
The Project Window 315
The Navigator Pane 317
The Utilities Pane 322
The Editor 323
The Project File and Its Dependents 325
What’s In the Project Folder 326
Groups 327
The Target 328
Build Phases 328
Build Settings 330
Configurations 331
Schemes and Destinations 333
From Project to Built App 335
Build Settings 338
Property List Settings 338
Nib Files 339
Additional Resources 340
Code Files 342
Frameworks and SDKs 343
The App Launch Process 345
The Entry Point 345
UIApplicationMain 346
App Without a Storyboard 348
Renaming Parts of a Project 349

7. Nib Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351


The Nib Editor Interface 352
Document Outline 353
Canvas 356
Inspectors and Libraries 358
Nib Loading 359
When Nibs Are Loaded 360
Manual Nib Loading 361
Connections 363
Outlets 363
The Nib Owner 364
Automatically Configured Nibs 368
Misconfigured Outlets 369
Deleting an Outlet 371
More Ways to Create Outlets 372

Table of Contents | vii


Outlet Collections 374
Action Connections 375
More Ways to Create Actions 377
Misconfigured Actions 379
Connections Between Nibs — Not! 379
Additional Configuration of Nib-Based Instances 380

8. Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
The Documentation Window 385
Class Documentation Pages 386
Quick Help 390
Symbol Declarations 392
Header Files 393
Sample Code 394
Internet Resources 394

9. Life Cycle of a Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397


Environmental Dependencies 397
Permissible Runtime Environment 398
Backward Compatibility 398
Device Type 400
Arguments and Environment Variables 401
Conditional Compilation 402
Version Control 404
Editing and Navigating Your Code 407
Autocompletion 409
Snippets 410
Fix-it and Live Syntax Checking 412
Navigation 413
Finding 415
Refactoring 416
Running in the Simulator 416
Debugging 417
Caveman Debugging 417
The Xcode Debugger 420
Testing 427
Unit Tests 428
Interface Tests 431
Clean 433
Running on a Device 433
Obtaining a Developer Program Membership 434
Signing an App 435

viii | Table of Contents


Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Automatic Signing 436
Manual Signing 439
Running the App 441
Managing Development Certificates and Devices 442
Profiling 442
Gauges 442
Memory Debugging 444
Instruments 445
Localization 448
Distribution 453
Making an Archive 453
The Distribution Certificate 454
The Distribution Profile 456
Distribution for Testing 457
Final App Preparations 458
Screenshots and Video Previews 461
Property List Settings 463
Submission to the App Store 464

Part III. Cocoa


10. Cocoa Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Subclassing 469
Categories and Extensions 472
How Swift Uses Extensions 472
How You Use Extensions 473
How Cocoa Uses Categories 473
Protocols 475
Informal Protocols 477
Optional Methods 477
Some Foundation Classes 480
NSRange and NSNotFound 481
NSString and Friends 483
NSDate and Friends 486
NSNumber 487
NSValue 489
NSData 490
NSMeasurement and Friends 491
Equality, Hashability, and Comparison 491
NSArray and NSMutableArray 494
NSDictionary and NSMutableDictionary 496

Table of Contents | ix
NSSet and Friends 496
NSIndexSet 497
NSNull 498
Immutable and Mutable 498
Property Lists 500
Codable 501
Accessors, Properties, and Key–Value Coding 504
Swift Accessors 505
Key–Value Coding 507
Uses of Key–Value Coding 508
KVC and Outlets 510
Cocoa Key Paths 510
The Secret Life of NSObject 511

11. Cocoa Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513


Reasons for Events 513
Subclassing 514
Notifications 516
Receiving a Notification 517
Unregistering 519
Posting a Notification 520
Timer 521
Delegation 523
Cocoa Delegation 523
Implementing Delegation 525
Data Sources 527
Actions 527
The Responder Chain 530
Deferring Responsibility 531
Nil-Targeted Actions 532
Key–Value Observing 533
Registration and Notification 534
Unregistering 535
Key–Value Observing Example 536
Swamped by Events 537
Delayed Performance 540

12. Memory Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543


Principles of Cocoa Memory Management 543
Rules of Cocoa Memory Management 544
What ARC Is and What It Does 545
How Cocoa Objects Manage Memory 546

x | Table of Contents
Autorelease Pool 547
Memory Management of Instance Properties 549
Retain Cycles and Weak References 550
Unusual Memory Management Situations 552
Notification Observers 552
KVO Observers 554
Timers 554
Other Unusual Situations 556
Nib Loading and Memory Management 556
Memory Management of CFTypeRefs 557
Property Memory Management Policies 559
Debugging Memory Management Mistakes 561

13. Communication Between Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563


Visibility by Instantiation 564
Visibility by Relationship 566
Global Visibility 567
Notifications and Key–Value Observing 569
Model–View–Controller 569

A. C, Objective-C, and Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

Table of Contents | xi
Preface

On June 2, 2014, Apple’s WWDC keynote address ended with a shocking announce‐
ment: “We have a new programming language.” This came as a huge surprise to the
developer community, which was accustomed to Objective-C, warts and all, and
doubted that Apple could ever possibly relieve them from the weight of its venerable
legacy. The developer community, it appeared, had been wrong.
Having picked themselves up off the floor, developers immediately began to consider
this new language — Swift — studying it, critiquing it, and deciding whether to use it.
My own first move was to translate all my existing iOS apps into Swift; this was
enough to convince me that Swift deserved to be, and probably would be, adopted by
new students of iOS programming, and that my books, therefore, should henceforth
assume that readers are using Swift.
That decision has proven prophetic. Programmers of iOS have flocked to Swift in
increasing numbers, and Swift itself has only improved. My iOS apps (such as Diabel‐
li’s Theme, LinkSame, Zotz!, TidBITS News, and my Latin and Greek flashcard apps)
have all been rewritten in Swift, and are far easier for me to understand and maintain
than their Objective-C originals.
Xcode 10 comes with Swift 4.2. The language has evolved greatly in its details and in
the nature of its integration with the Cocoa libraries that underlie iOS programming,
but its spirit has remained constant. The Swift language is designed from the ground
up with these salient features:
Object-orientation
Swift is a modern, object-oriented language. It is purely object-oriented: “Every‐
thing is an object.”
Clarity
Swift is easy to read and easy to write. Its syntax is clear, consistent, and explicit,
with few hidden shortcuts and minimal syntactic trickery.

xiii
Safety
Swift enforces strong typing to ensure that it knows, and that you know, what the
type of every object reference is at every moment.
Economy
Swift is a fairly small language, providing some basic types and functionalities
and no more. The rest must be provided by your code, or by libraries of code that
you use — such as Cocoa.
Memory management
Swift manages memory automatically. You will rarely have to concern yourself
with memory management.
Cocoa compatibility
The Cocoa APIs are written primarily in C and Objective-C. Swift is explicitly
designed to interface with most of the Cocoa APIs.
These features make Swift an excellent language for learning to program iOS.
The alternative, Objective-C, still exists, and you can use it if you like. Indeed, it is
easy to write an app that includes both Swift code and Objective-C code; and you may
have reason to do so. Objective-C, however, lacks the very advantages that Swift
offers. Objective-C agglomerates object-oriented features onto C. It is therefore only
partially object-oriented; it has both objects and scalar data types, and its objects have
to be slotted into one particular C data type (pointers). Its syntax can be difficult and
tricky; reading and writing nested method calls can make one’s eyes glaze over, and it
invites hacky habits such as implicit nil-testing. Its type checking can be and fre‐
quently is turned off, resulting in programmer errors where a message is sent to the
wrong type of object and the program crashes.
Recent revisions and additions to Objective-C — ARC, synthesis and autosynthesis,
improved literal array and dictionary syntax, blocks — have made it easier and more
convenient, but such patches have also made the language even larger and possibly
even more confusing. Because Objective-C must encompass C, there are limits to
how far it can be extended and revised. Swift, on the other hand, is a clean start. If
you were to dream of completely revising Objective-C to create a better Objective-C,
Swift might be what you would dream of. It puts a modern, rational front end
between you and the Cocoa Objective-C APIs.
Still, the reader may also need some awareness of Objective-C (including C). The
Foundation and Cocoa APIs, the built-in commands with which your code must
interact in order to make anything happen on an iOS device, are still written in C and
Objective-C. In order to interact with them, you might have to know what those lan‐
guages would expect.

xiv | Preface
Therefore, although I do not attempt to teach Objective-C in this book, I do describe
it in enough detail to allow you to read it when you encounter it in the documenta‐
tion and on the Internet, and I occasionally show some Objective-C code. Part III, on
Cocoa, is really all about learning to think the way Objective-C thinks — because the
structure and behavior of the Cocoa APIs are fundamentally based on Objective-C.
And the book ends with an appendix that details how Swift and Objective-C commu‐
nicate with one another, as well as explaining how your app can be written partly in
Swift and partly in Objective-C.

The Scope of This Book


This book is actually one of a pair with my Programming iOS 12, which picks up
exactly where this book leaves off. They complement and supplement one another.
The two-book architecture should, I believe, render the size and scope of each book
tractable for readers. Together, they provide a complete grounding in the knowledge
needed to begin writing iOS apps; thus, when you do start writing iOS apps, you’ll
have a solid and rigorous understanding of what you are doing and where you are
heading. If writing an iOS program is like building a house of bricks, this book
teaches you what a brick is and how to handle it, while Programming iOS 12 hands
you some actual bricks and tells you how to assemble them.
When you have read this book, you’ll know about Swift, Xcode, and the underpin‐
nings of the Cocoa framework, and you will be ready to proceed directly to Program‐
ming iOS 12. Conversely, Programming iOS 12 assumes a knowledge of this book; it
begins, like Homer’s Iliad, in the middle of the story, with the reader jumping with all
four feet into views and view controllers, and with a knowledge of the language and
the Xcode IDE already presupposed. If you started reading Programming iOS 12 and
wondered about such unexplained matters as Swift language basics, the
UIApplicationMain function, the nib-loading mechanism, Cocoa patterns of delega‐
tion and notification, and retain cycles, wonder no longer — I didn’t explain them
there because I do explain them here.
The three parts of this book teach the underlying basis of all iOS programming:
• Part I introduces the Swift language, from the ground up — I do not assume that
you know any other programming languages. My way of teaching Swift is differ‐
ent from other treatments, such as Apple’s; it is systematic and Euclidean, with
pedagogical building blocks piled on one another in what I regard as the most
helpful order. At the same time, I have tried to confine myself to the essentials.
Swift is not a big language, but it has some subtle and unusual corners. You don’t
need to dive deep into all of these, and my discussion will leave many of them
unexplored. You will probably never encounter them, and if you do, you will
have entered an advanced Swift world outside the scope of this discussion. To
give an obvious example, readers may be surprised to find that I never mention

Preface | xv
Swift playgrounds or the REPL. My focus here is real-life iOS programming, and
my explanation of Swift therefore concentrates on those common, practical
aspects of the language that, in my experience, actually come into play in the
course of programming iOS.
• Part II turns to Xcode, the world in which all iOS programming ultimately takes
place. It explains what an Xcode project is and how it is transformed into an app,
and how to work comfortably and nimbly with Xcode to consult the documenta‐
tion and to write, navigate, and debug code, as well as how to bring your app
through the subsequent stages of running on a device and submission to the App
Store. There is also a very important chapter on nibs and the nib editor (Interface
Builder), including outlets and actions as well as the mechanics of nib loading;
however, such specialized topics as autolayout constraints in the nib are post‐
poned to the other book.
• Part III introduces the Cocoa Touch framework. When you program for iOS, you
take advantage of a suite of frameworks provided by Apple. These frameworks,
taken together, constitute Cocoa; the brand of Cocoa that provides the API for
programming iOS is Cocoa Touch. Your code will ultimately be almost entirely
about communicating with Cocoa. The Cocoa Touch frameworks provide the
underlying functionality that any iOS app needs to have. But to use a framework,
you have to think the way the framework thinks, put your code where the frame‐
work expects it, and fulfill many obligations imposed on you by the framework.
To make things even more interesting, Cocoa uses Objective-C, while you’ll be
using Swift: you need to know how your Swift code will interface with Cocoa’s
features and behaviors. Cocoa provides important foundational classes and adds
linguistic and architectural devices such as categories, protocols, delegation, and
notifications, as well as the pervasive responsibilities of memory management.
Key–value coding and key–value observing are also discussed here.
The reader of this book will thus get a thorough grounding in the fundamental
knowledge and techniques that any good iOS programmer needs. The book itself
doesn’t show how to write any particularly interesting iOS apps, but it does constantly
use my own real apps and real programming situations to illustrate and motivate its
explanations. And then you’ll be ready for Programming iOS 12, of course!

Versions
This book is geared to Swift 4.2, iOS 12, and Xcode 10.
In general, only very minimal attention is given to earlier versions of iOS and Xcode.
It is not my intention to embrace in this book any detailed knowledge about earlier
versions of the software, which is, after all, readily and compendiously available in my
earlier books. The book does contain, nevertheless, a few words of advice about back‐
ward compatibility (especially in Chapter 9).

xvi | Preface
A word about method names. I generally give method names in Swift, in the style of a
function reference (as described in Chapter 2) — that is, the name plus parentheses
containing the parameter labels followed by colon. Now and then, if a method is
already under discussion and there is no ambiguity, I’ll use the bare name. In a few
places, such as Appendix A, where the Objective-C language is explicitly under dis‐
cussion, I use Objective-C method names.
Please bear in mind that Apple continues to make adjustments to the Swift language.
I have tried to keep my code up-to-date right up to the moment when the manuscript
left my hands; but if, at some future time, a new version of Xcode is released along
with a new version of Swift, some of the code in this book, and even some informa‐
tion about Swift itself, might be slightly incorrect. Please make allowances, and be
prepared to compensate.
Screenshots of Xcode were taken using Xcode 10 under macOS 10.13 High Sierra. I
have not upgraded my machine to macOS 10.14 Mojave, because at the time of this
writing it was too new to be trusted with mission-critical work. If you are braver than
I am and running Mojave, your interface may naturally look slightly different from
the screenshots (especially if you’re using “dark mode”), but this difference will be
minimal and shouldn’t cause any confusion.

Acknowledgments
My thanks go first and foremost to the people at O’Reilly Media who have made writ‐
ing a book so delightfully easy: Rachel Roumeliotis, Sarah Schneider, Kristen Brown,
Dan Fauxsmith, Adam Witwer, and Sanders Kleinfeld come particularly to mind.
And let’s not forget my first and long-standing editor, Brian Jepson, whose influence
is present throughout.
As in the past, I have been greatly aided by some fantastic software, whose excellences
I have appreciated at every moment of the process of writing this book. I should like
to mention, in particular:
• git (http://git-scm.com)
• Sourcetree (http://www.sourcetreeapp.com)
• TextMate (http://macromates.com)
• AsciiDoc (http://www.methods.co.nz/asciidoc)
• Asciidoctor (http://asciidoctor.org)
• BBEdit (http://barebones.com/products/bbedit/)
• EasyFind (http://www.devontechnologies.com/products/freeware.html)
• Snapz Pro X (http://www.ambrosiasw.com)
• GraphicConverter (http://www.lemkesoft.com)

Preface | xvii
• OmniGraffle (http://www.omnigroup.com)
The book was typed and edited entirely on my faithful Unicomp Model M keyboard
(http://pckeyboard.com), without which I could never have done so much writing over
so long a period so painlessly. For more about my physical work environment, see
http://matt.neuburg.usesthis.com.

From the Programming iOS 4 Preface


A programming framework has a kind of personality, an overall flavor that provides
an insight into the goals and mindset of those who created it. When I first encoun‐
tered Cocoa Touch, my assessment of its personality was: “Wow, the people who
wrote this are really clever!” On the one hand, the number of built-in interface
objects was severely and deliberately limited; on the other hand, the power and flexi‐
bility of some of those objects, especially such things as UITableView, was greatly
enhanced over their OS X counterparts. Even more important, Apple created a partic‐
ularly brilliant way (UIViewController) to help the programmer make entire blocks
of interface come and go and supplant one another in a controlled, hierarchical man‐
ner, thus allowing that tiny iPhone display to unfold virtually into multiple interface
worlds within a single app without the user becoming lost or confused.
The popularity of the iPhone, with its largely free or very inexpensive apps, and the
subsequent popularity of the iPad, have brought and will continue to bring into the
fold many new programmers who see programming for these devices as worthwhile
and doable, even though they may not have felt the same way about OS X. Apple’s
own annual WWDC developer conventions have reflected this trend, with their
emphasis shifted from OS X to iOS instruction.
The widespread eagerness to program iOS, however, though delightful on the one
hand, has also fostered a certain tendency to try to run without first learning to walk.
iOS gives the programmer mighty powers that can seem as limitless as imagination
itself, but it also has fundamentals. I often see questions online from programmers
who are evidently deep into the creation of some interesting app, but who are stymied
in a way that reveals quite clearly that they are unfamiliar with the basics of the very
world in which they are so happily cavorting.
It is this state of affairs that has motivated me to write this book, which is intended to
ground the reader in the fundamentals of iOS. I love Cocoa and have long wished to
write about it, but it is iOS and its popularity that has given me a proximate excuse to
do so. Here I have attempted to marshal and expound, in what I hope is a pedagogi‐
cally helpful and instructive yet ruthlessly Euclidean and logical order, the principles
and elements on which sound iOS programming rests. My hope, as with my previous
books, is that you will both read this book cover to cover (learning something new
often enough to keep you turning the pages) and keep it by you as a handy reference.

xviii | Preface
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
This book is not intended to disparage Apple’s own documentation and example
projects. They are wonderful resources and have become more wonderful as time
goes on. I have depended heavily on them in the preparation of this book. But I also
find that they don’t fulfill the same function as a reasoned, ordered presentation of
the facts. The online documentation must make assumptions as to how much you
already know; it can’t guarantee that you’ll approach it in a given order. And online
documentation is more suitable to reference than to instruction. A fully written
example, no matter how well commented, is difficult to follow; it demonstrates, but it
does not teach.
A book, on the other hand, has numbered chapters and sequential pages; I can
assume you know views before you know view controllers for the simple reason that
Part I precedes Part II. And along with facts, I also bring to the table a degree of expe‐
rience, which I try to communicate to you. Throughout this book you’ll find me
referring to “common beginner mistakes”; in most cases, these are mistakes that I
have made myself, in addition to seeing others make them. I try to tell you what the
pitfalls are because I assume that, in the course of things, you will otherwise fall into
them just as naturally as I did as I was learning. You’ll also see me construct many
examples piece by piece or extract and explain just one tiny portion of a larger app. It
is not a massive finished program that teaches programming, but an exposition of the
thought process that developed that program. It is this thought process, more than
anything else, that I hope you will gain from reading this 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 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 | xix
This element signifies a general note.

This element indicates a warning or caution.

Using Code Examples


Supplemental material (code examples, exercises, etc.) is available for download at
http://github.com/mattneub/Programming-iOS-Book-Examples.
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: “iOS 12 Programming Fundamentals
with Swift by Matt Neuburg (O’Reilly). Copyright 2018 Matt Neuburg,
978-1-492-04455-0.”
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 (formerly Safari Books Online) is a membership-
based training and reference platform for enterprise, gov‐
ernment, educators, and individuals.
Members have access to thousands of books, training videos, Learning Paths, interac‐
tive tutorials, and curated playlists from over 250 publishers, including O’Reilly
Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Profes‐
sional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press,
John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe
Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and
Course Technology, among others.

xx | Preface
For more information, please visit http://oreilly.com/safari.

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/ios12-prog-fundamentals.
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

Preface | xxi
PART I
Language

This part of the book teaches the Swift language, from the ground up. The descrip‐
tion is rigorous and orderly. Here you’ll become sufficiently conversant with Swift to
be comfortable with it, so that you can proceed to the practical business of actual
programming.
• Chapter 1 surveys the structure of a Swift program, both physically and concep‐
tually. You’ll learn how Swift code files are organized, and you’ll be introduced to
the most important underlying concepts of the object-oriented Swift language:
variables and functions, scopes and namespaces, object types and their instances.
• Chapter 2 explores Swift functions. We start with the basics of how functions are
declared and called; then we discuss parameters — external parameter names,
default parameters, and variadic parameters. Then we dive deep into the power
of Swift functions, with an explanation of functions inside functions, functions as
first-class values, anonymous functions, functions as closures, curried functions,
and function references and selectors.
• Chapter 3 starts with Swift variables — their scope and lifetime, and how they are
declared and initialized, along with features such as computed variables and set‐
ter observers. Then some important built-in Swift types are introduced, includ‐
ing Booleans, numbers, strings, ranges, tuples, and Optionals.
• Chapter 4 is all about Swift object types — classes, structs, and enums. It explains
how these three object types work, and how you declare, instantiate, and use
them. Then it proceeds to polymorphism and casting, protocols, generics, and
extensions. The chapter concludes with a discussion of Swift’s umbrella types,
Random documents with unrelated
content Scribd suggests to you:
came unto the sepulchre, bringing the spices which they had
prepared, and certain others with them. And they found the stone
rolled away from the sepulchre. And they entered in, and found not
the body of the Lord Jesus. And it came to pass, as they were
much perplexed thereabout, behold, two men stood by them in
shining garments. And as they were afraid, and bowed down their
faces to the earth, they said unto them, Why seek ye the living
among the dead? He is not here, but is risen: remember how he
spake unto you when he was yet in Galilee, Saying, The Son of
man must be delivered into the hands of sinful men, and be
crucified, and the third day rise again. And they remembered his
words. And returned from the sepulchre, and told all these things
unto the eleven, and to all the rest.—St. Luke xxiii: 56; xxiv: 1-9.

NOTE BY THE ARTIST


This and the following picture present the chief features of the
rock-hewn tomb referred to in Note facing picture No. 71. It is
about fifteen feet long by eleven feet wide, and eight feet in height,
and it is divided transversely by a flattened arch supporting the
roof. The single completed grave is formed by the erection on the
floor-level of a limestone slab in notches cut in the rock for its
support, thus forming, with the walls, a sort of built sarcophagus,
or coffin. An additional hollow, cut in the rock for the reception of
the head, explains the meaning of “the napkin that was about his
head” being “in a place by itself.” Sepulchres of this type are
comparatively rare, and, providing as it does a minimum of
accommodation for the labor expended on its construction, this
new tomb must obviously have belonged to a man of wealth.

72

And in examining the proof of the resurrection of Christ the most


important thing to notice is—the number and character of the
witnesses.
The first person who saw our blessed Lord, after he rose from the
dead, was Mary Magdalene. We read about this in St. Mark xi: 9. St.
John xx: 11-18. After this he appeared to certain other women, who
were returning from the sepulchre. St. Matt. xxviii: 9, 10. Then he
appeared to Simon Peter, alone. St. Luke xxiv: 34, I. Cor. xv: 5. His
next appearance was to two of his disciples, as they were walking
together from Jerusalem to a village called Emmaus. He had a long
talk with them and stopped and ate bread with them. St. Luke xxiv:
13-32. The fifth appearance of the risen Saviour was to ten of his
disciples, Thomas being the only one of them who was not there.
This was at Jerusalem, on the evening of the first glad Easter day.
St. John xx: 19-32. After this we hear nothing of him for a week. But
on the evening of “the first Sunday after Easter,” he made his sixth
appearance. On this occasion the eleven disciples were all together.
Thomas was with them now. They were sitting in a room, with the
door closed, and no doubt fastened, for fear of the Jews. Only one
subject could occupy their thoughts—and that was the resurrection
of their wonderful Master. Suddenly Jesus himself stood in the midst
of them, and said, “Peace be unto you.” In spite of all that he had
heard from the other disciples, Thomas declared he could not
believe it possible that Jesus had risen from the dead. When his
brethren told him that it was true, he said, “Except I shall see in his
hands the print of the nails, and put my finger into the print of the
nails, and thrust my hand into his side, I will not believe.” But on this
occasion the loving and gracious Saviour met his doubting disciple in
the very way in which he had desired to be met. For we read: “Then
saith he to Thomas, reach hither thy finger, and behold my hands:
and reach hither thy hand, and thrust it into my side; and be not
faithless, but believing.” St. John xx: 26-29.
The seventh appearance of the risen Saviour, was on the shore of
the sea of Galilee. A number of the apostles were together on this
occasion. It was one of the most touching and impressive of all his
interviews with them. The deeply interesting account of what took
place at this time is given in full in the twenty-first chapter of St.
John’s gospel; but we cannot enlarge on the subject now.
The eighth time that Jesus was seen after his resurrection was by
the eleven disciples again. We read in St. Matt. xxviii: 16—“Then the
eleven disciples went away into Galilee, into a mountain where Jesus
had appointed them.” This refers to St. Matt. xxvi: 32, when as they
were partaking together of the Lord’s Supper for the first time, after
referring to his death he said, “But after I am risen again, I will go
before you into Galilee.” We are not told where this meeting was
held, or what took place on that occasion.
The ninth appearance of the risen Lord, is that of which St. Paul
speaks in I. Cor. xv: 7, where he tells us that “he appeared to above
four hundred brethren at once.” The place here referred to is not
mentioned, and so cannot be known. It was probably in Galilee.
Jesus had spent most of his public life in that part of the country. He
had made most of his disciples there. It was proper, therefore, that
those disciples, who would, of course, hear of his death, should have
some public proof given them of the fact of his resurrection. No
doubt the eleven disciples went to Galilee after Jesus rose. They
would spread the news that he had risen, and that he was about to
show himself to his friends on a certain mountain. Nothing more
would be necessary anywhere to draw together a great concourse of
people than a report that one who was dead had come to life again,
and was about to show himself; and in this case where they greatly
loved him, and where, no doubt, many believed he would rise, they
would naturally come together in great numbers to see him once
more.
The tenth appearance of Christ after his resurrection was to the
apostle James. This is told us by St. Paul, who says I. Cor. xv: 7.
“After that he was seen of James.” This is not mentioned in any of
the gospels. But as Jesus was on earth for forty days after his
resurrection, it is most likely that he appeared often to his disciples,
and that only enough of the more prominent appearances were
mentioned, to prove the fact that he had risen.
The eleventh occasion on which Jesus was seen after his
resurrection was on the Mount of Olives, just before his ascension
into heaven. On this occasion all the eleven apostles were present,
and no doubt great numbers of his other disciples.
And then there was one other occasion on which Jesus appeared,
making twelve in all. This was after his ascension into heaven. To
this the apostle Paul refers, when he says, “And last of all he was
seen of me also.” I. Cor. xv: 8. This was when he had that wonderful
vision near Damascus. Then the great apostle to the Gentiles, saw
the same Lord Jesus, in the same body which had been seen by
others. Unless it were so, this would be no proof that Jesus was
risen from the dead. It was not a fancy therefore that he had seen
him. It was not revealed to him, that Jesus was risen. “Last of all he
was seen of me.” With his bodily eyes, St. Paul actually saw, in a
bodily form, that same Jesus who had died upon the cross; who had
been buried in that rocky sepulchre; who had risen from the dead
and had ascended into heaven. Such were the witnesses of the
resurrection, as to their number.
And now look at the character of these witnesses. They were
sensible men. They knew what they were doing. They could not be
mistaken about the fact of Christ’s resurrection. They had seen him
put to death upon the cross. They had seen him buried. On the third
day after his burial they had found his tomb empty. His body was
gone. Then they saw him alive. They could not be mistaken about
his person. They knew him too well for this. They had seen the print
of the nails in his hands. This made the proof of his resurrection
perfect.
And then they were honest men. They had no motive for
preaching the resurrection of Christ but the sincere belief that it was
true. If they could have made money or gained honor by preaching
the resurrection, that would have been a reason for their doing so
even if it had not been true. But the very opposite of this was the
case. Preaching the resurrection brought on them the loss of all they
had in the world. It caused them to be persecuted, imprisoned, and
put to death. And yet they went on preaching that Christ had risen.
And they would have been guilty of the greatest folly if they had
done this without being thoroughly convinced that it was true. But
they were perfectly satisfied of the truth of what they preached, and
this was the reason why they went on preaching it.
And then, if Christ had not risen from the dead, it would have
been the easiest thing in the world for the enemies of his cause to
have denied it. That would have ended the matter. But they never
did this. And the only reason why they did not do so, was that they
knew it was true that Christ had risen. They could not deny the fact.
And when we put these things all together, we see how perfectly
convincing is the proof of the resurrection of Christ.
And now let us look at some of the lessons taught us by our Lord’s
resurrection.
The first lesson we may learn from this great fact is about—the
power of christ.

We know of nothing that is harder to do than to bring the dead


back to life. Men can do many things, but this is one thing which
they cannot do. All the men in the world and all the angels in heaven
could never, by their own strength, restore life to the dead. When
the blood stops flowing through the veins, and the heart stands still,
there is nothing but the power of God that can make the heart begin
to beat, and the blood begin to flow again. But Jesus had the power
to do this. He raised Lazarus to life after he had lain in the grave
four days. And he did the same to the widow’s son, and to the
daughter of Jairus. And what he did for others in this matter, he did
for himself also. And he did it by his own power. On one occasion,
when speaking to his disciples about his death, or, as he called it,
laying down his life, he said, “I lay it down of myself; I have power
to lay it down, and I have power to take it again.” And he did this on
the morning of the resurrection. He exercised his own power to give
new life to his dead body. Here we have a grand lesson about the
power of Christ. And it is very comforting to know how great the
power of Jesus is, because we so often need to have him exercise
that power to help us when we are in trouble. And he is exercising
his power in this way continually.
Let us look at some of the ways in which he does this.
“The Power of Christ to Save.” A young man, the son of a pious
mother, was wandering away from the paths in which he had been
trained to walk. He had given up going to church, and in the
summer time generally spent his Sundays in sailing on the river in a
boat with his gay companions. One Sunday the boat upset. He could
not swim and he went down in the deep water. As he rose to the
surface for the last time, he was seized and his cold and apparently
lifeless body was brought to the shore. He was carried home.
Everything possible was done for his recovery, but for a long time it
seemed uncertain whether he would come back to life. There was a
feeble flutter about the wrist, just enough to keep hope alive.
His mother knelt by his bedside, and prayed in her agony that he
might be spared at least till he could seek and find pardon. As she
thus prayed, the cold hand held in hers gave a feeble pressure. The
eyelids quivered a little, but did not open. After a while he looked at
his mother, and said, in a low whisper, “Mother I am saved.”
Supposing that he meant saved from drowning, she replied, “Yes,
dear, thank God you are saved.” And then in broken sentences, with
long intervals between them, he gave this remarkable experience:
“Mother, I heard you praying: if I had died you would have
thought me lost: but I am saved. When I let go my hold upon the
boat, the thought flashed across my mind—I am lost. I am going
into eternity with all my sins unpardoned. I lifted up my heart to
heaven, and said, ‘God be merciful to me a sinner. Lord save me!’ I
seemed to hear a voice distinctly saying, ‘I will save thee, trust me.’ I
am sure it was the voice of Jesus. All my fear was gone. But after
that I knew nothing until I heard you praying for me. You would
have mourned for me as lost; but mother I am saved.”
And the result proved that he was right. As soon as he recovered
his health and strength, he gave up all his wicked ways, and lived
the life of an earnest and devoted Christian. How wonderful is the
power of Jesus to save!
“The Power of Jesus to Provide.” A Christian widow was dying. She
was very poor, and had four young children to leave helpless and
alone in the world. As she took leave of her little ones, Nettie, the
oldest girl, about fourteen years of age, said amidst heart-breaking
sobs and tears, “O, mother dear, what shall we do when you are
gone?”
“Nettie, darling,” said the mother, “God’s hand will help you. It is
an omnipotent hand. Never let go of it.”
The mother died and was buried. Towards evening of the next
day, little Dick, the youngest of the children, came to Nettie and
said, “Nettie, Dick’s awful hungry. Isn’t there a bit of crust
anywhere?” “Poor Dick,” said Nettie, “what shall we do?” And then,
remembering what her dying mother had said about the Omnipotent
hand, she dropped on her knees, and said, “O God, our God, and
our mother’s God, look on these hungry little ones, left in my care,
and send them some food for Christ’s sake. Amen.”
A rich merchant of the town was going home that evening. He
was a widower, but had no children. Without knowing why, he took a
different way home from the one ordinarily taken. As he walked
slowly along he happened to be just under the open window when
Nettie made that prayer for bread. The tone of deep sadness in it
touched his heart. He stopped. He knocked at the door. Nettie
opened it, and asked him in. He found out the sad condition of those
helpless orphans. He gave them money to get what they needed. He
continued to visit them, and finally became so much interested in
them that he took them to live with him in his own home. Nettie felt
the blessedness of holding on to the Omnipotent hand. Here we see
the power of Jesus to provide.
One other illustration shows us—“The Power of Jesus to Protect.”
A young Christian woman, whose family were very well off, was
confined to her sick bed for many years. She seldom had any one in
the room with her at night. On one occasion she lay awake about
midnight. The family were all asleep and the house was very still,
when the door of her chamber opened and a man walked softly in.
He came towards her bed and then stopped a moment. Her little
night lamp was shining on them both, from the stand by her
bedside. She did not scream, or cry. The robber looked at this lovely
girl, as she gazed on him with perfect calmness. Lifting her finger,
and pointing solemnly towards heaven, she said, “Do you know that
God sees you?” The man waited a moment, but made no reply. Then
he turned and walked quietly away. He had opened no other doors
than the street door and the door of her chamber. The omnipotent
hand was there, too. What a blessed thing it is to hold on to that
hand! Here we see the power of Jesus to protect. The power he had
to raise himself from the dead, he has still, to use for the help and
comfort of his people.
The second lesson to be learned from the resurrection is a lesson
about—the tenderness of Christ.
We learn this lesson from two little incidents connected with the
resurrection.
You remember that on the night of our Saviour’s trial, though all
the disciples forsook him, yet Peter was the only one of them who
denied him. In the very presence of Jesus, he declared with oaths
and curses, that he did not know him. How painful this must have
been to the blessed Saviour! It might have been expected that when
he met Peter again, for the first time after this, he would have had
some sharp rebuke to give him. But it was not so. Instead of this,
we find that when the angels at the empty tomb met the women
who had come early to anoint the body of Jesus, they told them that
he had risen from the dead, and then charged them to go and tell
the good news to “his disciples, and Peter.” He was the only one of
all the disciples who was mentioned by name in this message of the
angels. “Tell his disciples, and Peter!” How strange this was! The
angels did not do it of their own accord. No doubt Jesus had told
them to say this. And why did he do so? What led him to do it? It
was the tenderness of his loving heart. He knew how badly Peter
had been feeling about his shameful denial of him. He knew what
bitter tears he had been shedding over his sin. And he wished to let
him know that, notwithstanding what he had done, his injured
Master had no unkind feeling in his heart towards him. And so he
told the angels to say to the women that they should—“go tell his
disciples, and Peter,” that their Lord was risen. Here we see the
tenderness of Jesus.

Peter and John in the Sepulchre


Peter therefore went forth, and that other disciple, and came to
the sepulchre. So they ran both together: and the other disciple did
outrun Peter, and came first to the sepulchre. And he stooping
down and looking in, saw the linen clothes lying; yet went he not
in. Then cometh Simon Peter following him, and went into the
sepulchre, and seeth the linen clothes lie. And the napkin, that was
about his head, not lying with the linen clothes, but wrapped
together in a place by itself. Then went in also that other disciple,
which came first to the sepulchre, and he saw and believed. For as
yet they knew not the scripture, that he must rise again from the
dead. Then the disciples went away again unto their own home.—
St. John xx: 3-10.

NOTE BY THE ARTIST


The peculiar construction of the tomb furnishes an interesting
commentary upon the text, of which this picture is an illustration.
John is described as coming first to the sepulchre “and he stooping
down and looking in saw the linen clothes lying; yet went he not
in.” Why? Because from his position at the entrance, he could
perceive in the uncertain light the outline of the grave-clothes, and
he hastily concluded from their undisturbed appearance that the
body of his Master was still there. Peter, with characteristic
impulsiveness, entered in, and announced the startling discovery
that the body of Jesus was indeed removed. “Then went in also
that other disciple,” and further examination revealed the well-nigh
incredible fact that the grave-clothes and the head-napkin had
simply fallen together in a manner only compatible with the
supposition that they had not been unwound, but that in some
mysterious way the body of the Lord Jesus had actually risen
through the cerements of the tomb, leaving not a fold disturbed. As
yet the two disciples had not grasped the meaning of their Master’s
words that he should rise again, nor of the prophetic utterance of
David; but now, they “saw and believed.”

73

And then there was another incident connected with the


resurrection of Jesus which shows his tenderness still more
touchingly. He arranged matters so that Peter might have a private
interview with him, early in the day on which he rose from the dead.
St. Luke tells us, Ch. xxiv: 34, that Jesus “appeared unto Simon.”
And St. Paul says that—“he was seen of Cephas.” I. Cor. xv: 5. This
was a meeting that Peter had with the Master whom he had denied,
all by himself. We are not told what took place at this meeting. Peter
never said a word about it; and it was too sacred for any one else to
intrude upon. But we can very well imagine what was said and done.
We can imagine how the poor penitent disciple would sob, as if his
heart were breaking, when he saw his injured Master. We can fancy
we see him throwing himself at the feet of Jesus and bathing them
with bitter, burning tears, as he begged to be forgiven. And then we
can think of the kind and gentle words that Jesus would speak to
him. How tenderly he would assure him of his free forgiveness! How
he would tell him that he loved him still! and how willing he was to
put him back in his old place as a disciple, and let him go and preach
salvation for lost sinners through his death and resurrection! How
kind it was in Jesus thus to give Peter an opportunity of making up
with him, when they were all alone by themselves!
Let us never forget the tenderness of Jesus, as shown by these
two incidents. And let us try, like him, to be loving and gentle and
kind to all. See how much good may be done by those who imitate
the example of Christ in this respect.
“The Power of Kindness.” An English merchant had taken passage
on board a Turkish vessel, on the Mediterranean Sea. During the
voyage his attention was called to an interesting man on the vessel,
who was a slave belonging to the captain. He had frequent
conversations with him and found him to be a kind-hearted, active,
and intelligent person. In the course of their conversations together,
he learned that the man had been born free, but had been taken
captive in war, and was now a slave for life.
The merchant felt a great sympathy for the poor captive and had
a desire to get him released. He inquired what it would cost to
purchase his freedom. The sum named was more than the whole
profit of his voyage. Still he could not give up the thought. He
offered the captain a price for his slave. The offer was accepted. The
slave overheard this conversation. He supposed the merchant was
going to purchase him, that he might keep him as his own slave.
This made him very angry. He sprang forward and said, with great
excitement, “You call yourself a lover of freedom, an enemy to
slavery, wherever found, and yet you are purchasing me!”
The merchant turned and looked kindly on him, as he calmly said,
“My friend, I have bought you to set you at liberty. Now you are a
free man.”
In a moment the storm of passion was stilled. The slave burst into
tears; and falling at the feet of his deliverer, he exclaimed, “You have
taken my heart captive! I am your servant forever!”
Few of us may have the opportunity of showing kindness as this
merchant did. But every boy and girl in the land may follow the
example of the noble lad whose kindness to the aged is told in these
simple lines:

SOMEBODY’S MOTHER.

“The woman was old, and ragged and gray,


And bent with the chill of the winter’s day;
The street was wet with recent snow,
And the woman’s feet were aged and slow.
She stood at the crossing, and waited long,
Alone, uncared for, amid the throng
Of human beings who passed her by,
None heeded the glance of her anxious eye.

“Down the street, with laughter and shout,


Glad in the freedom of ‘school let out,’
Came the boys, like a flock of sheep,
Hailing the snow piled white and deep.
Past the woman so old and gray,
Hastened the children on their way,
Nor offered a helping hand to her
So meek, so timid, afraid to stir
“Lest the carriage-wheels, or the horses’ feet
Should crowd her down in the slippery street.
At last came one of the merry troop,
The gayest laddie of the group;
He paused beside her and whispered low
‘I’ll help you across if you wish to go.’
Her aged hand on his strong young arm
She placed, and so, without hurt, or harm,

“He guided the trembling feet along,


Glad that his own were firm and strong.
Then back again to his friends he went,
His young heart happy and well content.
‘She’s somebody’s mother, you know,
Altho’ she is aged, and poor, and slow;
And I hope some fellow will lend a hand
To help my mother, you understand,

“‘If ever she’s poor, and old, and gray,


When her own dear boy is far away.’
And ‘somebody’s mother’ bowed low her head
In her home that night, and the prayer she said
Was, ‘God be kind to that noble boy,
Who is somebody’s son, and pride, and joy!’”

Let us never forget the lesson of tenderness which Jesus taught


on the morning of his resurrection.
The only other lesson, in connection with the resurrection of
Christ, of which we would now speak is about—the way of showing our
love to him.

This lesson was taught on the shore of the Sea of Galilee. Some of
the disciples of Jesus had gone back to their old trade of fishing. On
one occasion they had been out all night, but had caught nothing.
The next morning, Jesus stood on the shore of the lake, but they did
not know him. He asked them if they had anything to eat. They said
no. He told them to cast the net on the right side of the ship, and
they would find plenty of fish. They did so, and their nets were filled
at once. Then John, the loving disciple, was the first to find out who
it was. He said to Peter, “It is the Lord.” As soon as Peter heard this,
he fastened his fishing coat about him, plunged into the sea, and
swam to the shore. The other disciples rowed to land in their boat.
As soon as they landed, they found a fire of coals, with fish and
bread all ready for eating. Jesus invited them to come and dine with
him. They did so, and when the dinner was over, he had a long
conversation with them. As they were talking together, he said to
Peter, “Simon, son of Jonas, lovest thou me?” He saith unto him,
“Yea, Lord; Thou knowest that I love thee.” He saith unto him, “Feed
my lambs.” This question was repeated by Jesus the second and the
third time. Peter gave the same answer each time. The reply of
Jesus was—“Feed my sheep.” The lambs of Christ’s flock mean the
children, or young members of his church. The sheep of Christ mean
the older members of his church. By feeding his lambs and his
sheep, Jesus meant teaching his people, both young an old, about
himself, and what he has done for their salvation. And by what Jesus
said on this occasion, he meant to teach Peter, and you and me, and
all his people, that if we really love him, the way in which he wishes
us to show that love, is by being kind to others—by teaching them
about him, and by trying to get them to love and serve him, too.
This is a good lesson for ministers to learn; for parents, for
teachers, and for all who love Jesus. When we have found what a
faithful friend, what a loving Saviour, what a kind and tender
comforter we have in him, then he wishes us to do all we can to
help others to know him, and love him, and serve him. This is what
we should all be trying to do.
Let us look at some of the ways in which we may do this.
“The Unexpected Friend.” The Rev. Mr. Moffatt,—the missionary to
Southern Africa, tells an interesting story which illustrates very
strikingly this part of our subject. “In one of my early journeys in this
land,” he says, “I came, with my companions, to a heathen village
on the banks of a river. We had travelled far, and were hungry and
thirsty and very weary. The people of the village would not let us
come near them. We asked for water and they would not give us
any. We offered to buy milk, but they refused to sell us any. We had
no prospect but that of spending the night without anything to eat,
or to drink. But at the close of the day a woman came to us from
the village. She bore on her head a bundle of wood, and had a
vessel of milk in her hand. Without saying a word, she handed us
the milk. She laid down the wood and returned to the village.
Presently she came again with a cooking vessel on her head, with a
leg of mutton in one hand and a vessel of water in the other. Silently
she kindled the fire and put on the meat. Again and again we asked
her who she was and why she was doing all this for us strangers. At
last she said that years before there had been a missionary in her
neighborhood. He had gone away a long while ago; but from him
she had learned to know the Saviour. ‘I love him,’ she said, ‘whose
servants you are, and I wish to show my love to him by doing what I
can to help you.’ ‘I asked her,’ said Mr. Moffatt, ‘how she, alone in
that dark land, without a minister, without a church, and without any
Christian friends, had kept up the light of God in her heart?’ She
drew from her bosom a soiled and worn copy of the New Testament,
which the missionary had given her. ‘This,’ she said, ‘is the fountain
from which I drink; this is the oil that makes my lamp burn.’”
“How a Boy Showed his Love for Christ.” Some time ago a dreadful
accident took place on the river Thames, in England. A steamer,
called the Princess Alice, when crowded with passengers, on an
excursion, was run into by another vessel and sunk. Fearful screams
filled the air as the great crowd of people were plunged into the
water. Among those who were drawn to the spot was a good
Christian boy, about sixteen years of age, who worked in the
neighborhood. Being a good swimmer, he at once plunged into the
water, took hold of the first struggler he met with, and bore him
away in safety to the shore. He did the same the second time, and
then the third. As he was nearing the shore the third time he saw a
small bundle floating on the water, which he thought must be a
baby. He caught it with his teeth, and thus was the means of saving
four lives on that terrible occasion. By the time he had done this, his
strength was exhausted, and he was unable to venture again among
the drowning ones. But he carried the baby home to his mother’s
humble dwelling, and placing the little orphan in her arms, he said,
“Here, mother, suppose you nurse this baby for our blessed Saviour;
and I will work for its support as long as I live.”
A noble boy that was! and a beautiful illustration he gave of the
way in which we should show our love to Jesus, by feeding and
taking care of his lambs, and doing good to his people.
I never saw the lesson now before us better expressed than in the
following simple lines:

SHINING FOR JESUS.

“Are you shining for Jesus children? You have given your
hearts to Him;
But is the light strong within them, or is it but pale and dim?
Can everybody see it—that Jesus is all for you?
That your love to Him is burning with radiance warm and
true?
Is the seal upon your forehead, so that it must be known
That you are ‘all for Jesus,’ that your hearts are all His own?

“Are you shining for Jesus, children, so that the holy light
May enter the hearts of others, and make them glad and
bright?
Have you spoken a word for Jesus, and told to some around

Who do not care about Him,—what a Saviour you have
found?
Have you lifted the lamp for others, that has guided your
own glad feet?
Have you echoed the loving message, that seemed to you so
sweet?
“Are you shining for Jesus, children, shining just
everywhere?
Not only in easy places, not only just here or there?
Shining in happy gatherings, where all are loved and known?
Shining where all are strangers,—shining when quite alone?
Shining at home, and making true sunshine all around?
Shining at school, and faithful—perhaps among faithless—
found?

“Oh! rise, and ‘watching daily,’ ask Him your lamps to trim,
With the fresh oil which He giveth, that they may not burn
dim.
Yes, rise and shine for Jesus! Be brave, and bright and true,
To the true and loving Saviour, who gave Himself for you.
Oh! shine for Jesus, children! and henceforth be your way
Bright with the light that shineth unto the perfect day!”
THE ASCENSION
We come now to the last event in the history of our Saviour’s life
on earth. His work is done. His teachings are finished. His sufferings
are ended. Nothing remains for him to do but to return to heaven,
from whence he came, and take his seat at the right hand of God.
And this is the subject we are now to consider—The Ascension of
Christ.
And in considering it, the first thing for us to notice is—the time of
the Ascension.
And in all the New Testament there is only one place in which
anything is said about the time of the ascension. Indeed it is
surprising that so little is said about it altogether. Two of the gospels,
that of St. Matthew and St. John, have not a word to say on the
subject. And the other two do not say much. All that St. Mark says
about it is in a single verse. We read thus in Chap. xvi: 19:—“So,
then, after that the Lord had spoken unto them, he was received up
into heaven, and sat on the right hand of God.” There are two verses
in St. Luke in which the ascension is spoken of. In Ch. xxiv: 50, 51,
we find the ascension thus described: “And he led them out as far as
to Bethany; and he lifted up his hands and blessed them. And it
came to pass, while he blessed them, he was parted from them, and
carried up into heaven.”
The most particular account of the ascension that we have in the
New Testament is given in the “Acts of the Apostles.” In the first
chapter of this book we are told that the ascension took place “forty
days after the resurrection.” We are told of the “many infallible
proofs” that he had risen, and how he spoke to them “of the things
pertaining to the kingdom of heaven.” And he “commanded them
not to depart from Jerusalem,” until they should “be baptized with
the Holy Ghost,” which was to take place “not many days” after his
ascension. “Ye shall receive power,” said he, “after that the Holy
Ghost is come upon you.” Then he told them how “they should be
witnesses for him, both in Jerusalem and in all Judea, and unto the
uttermost parts of the earth.” “And when he had spoken these
things, while they beheld, he was taken up; and a cloud received
him out of their sight.”
And then we read about the two angels who appeared to the
disciples and told them that “this same Jesus, which was taken up
from you into heaven, shall so come, in like manner, as ye have seen
him go into heaven.”
In the third verse of this chapter we have the only information
which the whole Bible gives us about the time of the ascension. Here
we learn that this great event took place on the fortieth day after his
resurrection. We are not told why the ascension was delayed so long
after Jesus had risen from the dead. But, no doubt, there were good
reasons for it. And it may be that we shall know all about these
reasons hereafter, though we do not know them now.
If we begin and count the forty days from Easter Sunday, the
fortieth day will always come on the Thursday in the fifth week after
Easter. And this day is always kept in the Church of England, in the
Protestant Episcopal Church in this country, and in some other
churches in memory of the important event we are now considering.
It is called Ascension Day, or Holy Thursday; and the portions of
Scripture read on that day all have reference to the ascension of our
blessed Lord. And this is all that need be said about the time of the
ascension.
The place where the ascension occurred is the next thing to
notice.
From what we read in the gospel of St. Luke, we might suppose it
was from Bethany that Jesus made his ascension. Here it says, “He
led them out as far as to Bethany, and he lifted up his hands and
blessed them. And it came to pass, while he blessed them, he was
parted from them, and carried up into heaven.” St. Luke xxiv: 50,
51. But in the first chapter of the Acts of the Apostles, after
describing his ascension, we read that the disciples “returned unto
Jerusalem from the Mount called Olivet.” Acts i: 12. But there is no
contradiction here; for Bethany, the home of Lazarus and his sisters,
was on the Mount of Olives. It was situated just below the top of the
Mount, on the other side from Jerusalem. And so we know that it
was either from the village of Bethany, or from some spot between
that and the summit of the Mount, that Jesus made his ascension.
When he was here on earth he often went to the Mount of Olives. It
was from this mountain that “Jesus beheld the city and wept over it,”
when he used that beautiful illustration, “how often would I have
gathered thy children together, even as a hen gathereth her chickens
under her wings, and ye would not!” It was on this mountain that he
sat with his disciples when he gave that wonderful prophecy about
the destruction of Jerusalem, and his coming again into our world, of
which we read in the twenty-fourth chapter of St. Matthew.
The Mount of Olives was the last spot of this earth on which the
feet of the blessed Saviour stood before he went up to heaven. And
when he comes again into our world he will return to the place from
which he ascended. This we are told by the prophet Zechariah. For it
is when he is speaking of the return of Jesus from heaven that he
says—“And his feet shall stand at that day on the Mount of Olives.”
Ch. xiv: 4. This thought very naturally makes Olivet an interesting
place to visit.
Jesus Revealeth Himself to Mary
Magdalene
Mary stood without at the sepulchre weeping: and as she wept,
she stooped down, and looked into the sepulchre. And seeth two
angels in white sitting, ... where the body of Jesus had lain. And
they say unto her, Woman, why weepest thou? She saith unto
them, Because they have taken away my Lord, and I know not
where they have laid him. And when she had thus said she turned
herself back, and saw Jesus standing, and knew not that it was
Jesus. Jesus saith unto her, Woman, why weepest thou? whom
seekest thou? She, supposing him to be the gardener, saith unto
him, Sir, if thou have borne him hence, tell me where thou hast laid
him, and I will take him away. Jesus saith unto her, Mary. She
turned herself, and saith unto him, Rabboni; which is to say, Master.
Jesus saith unto her, Touch me not; for I am not yet ascended to
my Father: but go to my brethren, and say unto them, I ascend
unto my Father, and your Father; and to my God, and your God.
Mary Magdalene came and told the disciples that she had seen the
Lord, and that he had spoken these things unto her.—St. John xx:
11-18.

NOTE BY THE ARTIST


It would appear that Mary Magdalene was one of the little
company of faithful women who came very early in the morning to
the sepulchre, but that she had hastened back to the city before
the angelic revelation to her companions. Once more bending her
steps in sorrow to the empty grave, to Mary, loving greatly because
greatly forgiven, was vouchsafed the privilege of first beholding her
risen Lord and Master—the same, yet wondrously changed, so that
now, as on subsequent occasions when Jesus appeared to his
disciples and “their eyes were holden that they should not know
him,” it was not by outward form and aspect, but by words of love
and tenderness such as he alone could utter, that his identity was
revealed. Although the external aspect of the sepulchre bears little
resemblance to that which it presented in former times, the rock-
cut grooves which still remain, render it abundantly evident that the
entrance with its rolling stone, and the method by which the latter
was “sealed,” were such as have been already described in my Note
to the picture “The Resurrection of Lazarus.”

74
I remember, when at Jerusalem, a very pleasant visit we made to
this sacred Mount. It was at the close of a Sunday afternoon. The
sun went down as we stood there. And there was something very
sweet and solemn in the thought that Jesus, our glorious Lord, had
once stood on that Mount, near where we then were. It was from
there that his disciples saw him go into heaven. And when he comes
back from heaven, his feet will stand again upon the Mount of
Olives. And so, when we think of our Saviour going back to heaven,
we may always remember that some spot on or near the top of the
Mount of Olives was the place of the ascension.
The Manner of the Ascension—is the third thing of which to speak.
It was a visible ascension. There are only two other persons
spoken of in the Bible as having gone up from earth to heaven in a
bodily form. One of them was “Enoch, the seventh from Adam.” His
ascension was not visible. No one saw him go. It took place in
secret. We are told in one place that “he was not, for God took him.”
In another place it is said, “he was translated.” This is all we know
about the translation of Enoch.
The other case mentioned in the Bible is that of the prophet Elijah.
His ascension was visible, indeed, but it was only seen by one
person, and that was the prophet Elisha. But it was different with
the ascension of Christ. This did not take place in secret, but in
public. It was not only visible, but was witnessed by a crowd of
people. All the eleven disciples were there to see it. And there can
be no doubt that a great many others, besides the apostles, were
there too. And they all saw him, as he rose from the midst of them,
and went up to heaven. It was a visible ascension.
It was a calm and tranquil ascension. It was not done in a hurry.
Solomon tells us, when speaking of God’s doings, that his
“judgments are not executed speedily.” This means they are not
done in haste. God never works in a hurry. After he gave to Adam
the first promise, of a future deliverer from the effects of sin, he
waited more than four thousand years before he sent him into the
world. And, after Christ had risen from the dead, he was not in haste
to leave the world, and go back to heaven. We might have expected
that he would just have shown himself once or twice to his disciples,
so as to make them sure of his resurrection, and would have left
immediately for heaven. But it was not so. Instead of this he
remained here for forty days. He did not spend all this time in the
company of his disciples. He only showed himself to them from time
to time, and talked with them “of things pertaining to the kingdom
of God.” And when at last these days were over, and the time came
for him to go, still there was no haste about it. He did not go up with
a rush, as a rocket goes up. That would not have been like him. But,
as he stood on the Mount of Olives talking to his disciples, who were
standing round him, he began to rise slowly and silently towards
heaven. And as he began, so he went on. Slowly and silently he
continued to rise. Upwards he went, higher—and higher,—till at last
a cloud received him out of their sight. That cloud became, as it
were, the chariot in which he was carried up in triumph to heaven. It
was a calm and tranquil ascension.
It was a blessed ascension. You know how it is at the close of a
service in church. The minister lifts up his hands to bless the people,
or as we say, to pronounce the benediction. And this was what Jesus
was doing at the very moment of his ascension. He knew that the
time had come for him to go. He knew that he was about to be
separated from his disciples, and that they would see him no more
in this world. So he lifted up his hands to bless them; and, while he
was in the act of speaking those words of blessing, the ascension
took place. As his hands were stretched out to bless his disciples, he
rose calmly in the midst of them and went back to heaven, from
whence he came.
It was said of him before he came into our world, that—“men
should be blessed in him:” Ps. lxxii: 17. He was the promised seed of
Abraham, in whom it was declared that “all the nations of the earth
should be blessed.” Gen. xxii: 18. The blessing of the world was
wrapped up in Jesus. When he came into the world, he came to
bless it. And when he began his public ministry in the Sermon on the
Mount, the first thing of which he had to speak was the blessings he
came to bring. We read, “And when he was set, his disciples came to
him, and he opened his mouth and taught them, saying, Blessed are
the poor in spirit, &c. Blessed are they that mourn, &c. Blessed are
the meek, &c. Blessed are the merciful, &c. Blessed are the pure in
heart, &c.” He began his work in blessing; he continued it in
blessing; and he ended it in blessing. But the work of blessing in
which he had been engaged here did not cease when he ascended
into heaven. He has been carrying on the work of blessing men ever
since he ascended. He went to heaven to procure for his people the
best of all possible blessings. He told his disciples that it was
necessary for him to leave them and go to heaven; because if he did
not go the Holy Ghost would not come to them; but that when he
went to heaven he would send the Spirit to be their helper and
comforter. It is the Holy Spirit who helps us to understand the
Scriptures and who teaches us how to love and serve God. And
whatever helps us to do this is the best thing—the greatest blessing
for us. And when we know that Jesus went to heaven to obtain for
us the help of God’s grace and Spirit, we may well say that the
ascension of Christ was a blessed ascension.
The only other thing we have to say about the ascension of Christ
is that it was a wonderful ascension. There were two wonderful
things connected with it. It was wonderful to think where he went.
He did not go simply to join the company of the angels, who have
always lived in heaven, and of the good people who went there
when they died. No; but he went where no one else had ever gone
before, and where no one else could go. When he arrived in heaven,
he rose above all the company that was there, and took his seat at
the right hand of the throne of God. This was wonderful, indeed.
When Jesus was on earth, he was so poor that he “had not where to
lay his head.” He was despised and persecuted; “a man of sorrows
and acquainted with grief.” He was put to death as a criminal, by
being crucified between two thieves. But when he ascended into
heaven it was to take his place “far above all principalities and
powers.” And so his ascension was wonderful when we think—where
he went.
And it was wonderful, too, when we think how he went there. If
he had left his human body behind him, and had ascended to
heaven simply in his divine nature, as God, it would not have been
so wonderful. But he did not do this. He took his human body with
him. The body that was nailed to the cross and laid in the grave, he
took with him to heaven. He ascended, indeed, as the Son of God.
But that was not all. No, for he ascended as the Son of man, too. It
was Jesus Christ who ascended into heaven. But it was our human
nature, as well as the divine nature which helped to make up the
person of Jesus Christ. And so when he ascended into heaven, and
sat down at the right hand of the throne of God, he took our human
nature with him. He took a body like yours and mine, up to that high
and glorious place. And he is sitting there now, on the throne of
God, as our brother. This is the most surprising thing connected with
the great event we are now considering. This shows us how
wonderful the ascension of Christ was.
And so, in studying this subject, these are the things about it that
we have noticed, viz.: the time of the ascension—forty days after the
resurrection; the place of the ascension—the Mount of Olives; the
manner of the ascension—visible—calm and tranquil—blessed—and
wonderful.
There are several lessons that may be learned from the ascension
of our Saviour, but we can only speak of one. This is the lesson of
obedience to the command of Christ.
Just before he went up to heaven, Jesus said to his disciples—“Go
ye into all the world, and preach the gospel to every creature.” St.
Mark xvi: 15. This is the last command he gave to his people. He
kept it till now because he wished it to be especially remembered.
When we lose a father, or mother, or a friend whom we love very
much, we listen attentively to the words spoken by that friend as we
gather round the dying bed. We may forget some things spoken by
him in the days of his health and strength, but those last words that
were spoken just before he died, we always remember. They seem
very sacred to us, and we pay particular attention to them. And no
doubt this was the reason why Jesus kept this command about the
missionary work he wishes his people to engage in, till now. He had
finished his work for them. He had died for them. He had done all
that was necessary for them to be saved, and to be happy with him
forever in heaven. He knew how much they ought to love him for all
this. And he knew that those who really did love him would wish to
show their love by doing what he had told them to do. And so he
kept this—the most important of all his commands—to the last. He
wished it to be connected with the thought of his leaving the world
and going back to heaven. And as they gathered round him, to see
him and hear him for the last time on earth, he spoke these words:
—“Go, ye, into all the world, and preach the gospel to every
creature.” He did not speak them for the apostles or the early
Christians only. No; but he spoke them for you, and for me, and for
all his people, till the end of time. He intended his church to be a
missionary church. He intended that all the members of that church
should feel an interest in the missionary work, and that they should
do all they can to help it on. This command is very broad. It takes in
“all the world,” and “every creature.” We have no right to make the
field for this work narrower than Jesus made it. And, until the gospel
has been preached in “all the world,” and until “every creature” has
heard it, this command of Christ is binding upon all his loving
people. If we do not have the missionary spirit which these words
require us to have, that is, if we are not trying all we can to bring
“every creature,” in “all the world,” to be the friend and servant of
Jesus and to be saved by him, then, it is clear, either that we are not
loving Jesus as we ought to love him; or else, we are not showing
our love for him in the way in which he wishes us to show it. He
says, “If ye love me, keep my commandments.” And this is his last
and most solemn command for us to remember, and keep.
When he says—“Go ye into all the world and preach,” he does not
mean that all his people must leave their homes and go out as
ordained ministers. What he means is that whether we go out as
missionaries, or not, we must have the missionary spirit, and must
do all we can to help the missionaries in their work. We must try to
get those around us to know, and love, and serve Jesus. And the
important question for us all to consider here is—how can we do
this? In answering this question, let me point out four ways in which
this may be done.
We can be missionaries, and help to preach the gospel, by our
example.
A little boy named Ernest had begun to love the Lord Jesus Christ
and to be a Christian. One day he said to his aunt, “Now I want to
grow up a big man, and then I will be a minister and preach to lots
of people about Jesus.”
His aunt told him that he need not wait till he was a man before
he began to preach. “Try now, every day, to learn your lessons well,”
said his aunt; “to be kind, and gentle to all, and try by God’s help to
overcome your bad temper, and so, by your example you may be
preaching Jesus every day.”
“The Children’s Service.” A little girl went to a Children’s service
one Sunday afternoon. On going home she told her mother about it.
“What led you to go, Mary?” asked the mother.
“I went, mamma,” she said, “because I was invited to come by a
kind boy that I met in the street yesterday. I saw him stop and
stroke a donkey that was frightened by a cruel boy. Then he kindly
picked up my ball that was rolling away and returned it to me. As he
did this he handed me a paper about the children’s service, and
invited me to come. I knew he was a good boy because he was so
kind and had such a happy face. He said he was sure I would like
the services; and I did like them. And I mean to go every time.”
“A Young Hero.” Thirty years ago a boy had given his heart to the
Saviour. He had been confirmed and joined the church. The next day
he went to school. Some of the wild boys of the school heard that he
had joined the church, and they made up their minds to have some
fun with him about it. At recess time they formed a ring about him,
and cried out:
“Oh! here is the good boy, Charley! He is going to be a Christian!”
And what did Charley do? Did he feel ashamed and try to steal
away? Did he get angry, and hit, or kick, or speak cross to them?
No. But he calmly looked the rude boys in the face, and said, in a
manly way: “Yes, boys, I am trying to be a Christian. And isn’t that
right?”
The boys’ consciences told them he was right. They felt ashamed.
The ring was broken up at once, and Charley had no more trouble.
He was preaching by his example.
“A Beautiful Illustration.” Mary Duncan was a little girl, only four
years old, who was trying to be a Christian. This incident shows us
that even at that early age she was beginning to preach, and do
good by her example.
One day she was playing with her little brother. In a fit of anger he
struck her in the face. But instead of screaming out, or striking him
back, she quietly turned to him the other cheek; and said, “There
Corie, now strike that!” The uplifted hand was dropped. The tears
came into her brother’s eyes. He kissed her, and said—“Forgive me,
sister, and I’ll never strike you again.”
When Mary was asked what led her to do so, her reply was that
she had heard her papa read out of the Bible, at prayers that
morning, what Jesus had said about it.
And so if we try to be like Jesus, we may be helping to keep his
last command, and to preach the gospel—by our example.
Another way in which we may do this is—by our efforts. This
means by what we say and do to show that we love him, and to try
to bring others to do so too. We find many illustrations of the way in
which this may be done.
“Preaching in the Hayfield.” A good, earnest minister of the gospel
was riding one day past a hayfield. A sudden shower was coming up.
He saw a farmer, who never went to church, sending off in haste for
a horse to draw his hay in before the rain came. The minister
stopped and offered his horse to do the work. It was declined; but
the minister insisted, and pulling off his coat, unhitched his horse
and went to work helping the farmer to load the hay. They got in
several loads, and when the last load was in the barn, and the rain
came pouring down, the farmer drew out his pocket book, and said:
“How much do I owe you, sir, for your help?”
“Oh, nothing,” said he, “nothing at all.”
But the farmer insisted on paying him for his work.
“Well, my friend,” said the minister, “did you ever hear an Irishman
preach?”
“No,” said the farmer.
“Well, you come next Sunday, and hear me preach, and we’ll call it
even.”

You might also like