Instant Ebooks Textbook iOS 12 Programming Fundamentals With Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg Download All Chapters
Instant Ebooks Textbook iOS 12 Programming Fundamentals With Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg Download All Chapters
com
https://textbookfull.com/product/ios-12-programming-
fundamentals-with-swift-swift-xcode-and-cocoa-basics-5th-
edition-matt-neuburg-3/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/ios-12-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-5th-edition-matt-neuburg-2/
textboxfull.com
https://textbookfull.com/product/ios-12-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-5th-edition-matt-neuburg-3/
textboxfull.com
https://textbookfull.com/product/ios-10-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-3rd-edition-matt-neuburg/
textboxfull.com
https://textbookfull.com/product/ios-11-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-4th-edition-matt-neuburg/
textboxfull.com
iOS 13 Programming Fundamentals with Swift Swift Xcode and
Cocoa Basics 1st Edition Matt Neuburg
https://textbookfull.com/product/ios-13-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-1st-edition-matt-neuburg/
textboxfull.com
https://textbookfull.com/product/ios-14-programming-fundamentals-with-
swift-covers-ios-14-xcode-12-and-swift-5-3-7th-edition-matt-neuburg/
textboxfull.com
https://textbookfull.com/product/programming-ios-14-11th-edition-matt-
neuburg/
textboxfull.com
https://textbookfull.com/product/learn-ios-11-programming-with-
swift-4-craig-clayton/
textboxfull.com
https://textbookfull.com/product/programming-ios-12-dive-deep-into-
views-view-controllers-and-frameworks-1st-edition-matt-neuburg/
textboxfull.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 [email protected].
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
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
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
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
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
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
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.
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.
xviii | Preface
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.
Preface | xix
This element signifies a general note.
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:
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‐
[email protected].
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,
such as Any and AnyObject, and collection types — Array, Dictionary, and Set
(including option sets).
• Chapter 5 is a miscellany. We start with Swift’s flow control structures for branch‐
ing, looping, and jumping, including error handling. Then I describe Swift access
control (privacy), introspection (reflection), and how to create your own opera‐
tors. There follows a discussion of some recently added Swift language features:
synthesized protocol implementations, key paths, and dynamic member lookup.
The chapter concludes by considering Swift memory management.
CHAPTER 1
The Architecture of Swift
It will be useful at the outset for you to have a general sense of how the Swift language
is constructed and what a Swift-based iOS program looks like. This chapter will sur‐
vey the overall architecture and nature of the Swift language. Subsequent chapters
will fill in the details.
Ground of Being
A complete Swift command is a statement. A Swift text file consists of multiple lines
of text. Line breaks are meaningful. The typical layout of a program is one statement,
one line:
print("hello")
print("world")
3
print(
"world")
Comments are everything after two slashes in a line (so-called C++-style comments):
print("world") // this is a comment, so Swift ignores it
You can also enclose comments in /*...*/, as in C. Unlike C, C-style comments can
be nested.
Many constructs in Swift use curly braces as delimiters:
class Dog {
func bark() {
print("woof")
}
}
By convention, the contents of curly braces are preceded and followed by line breaks
and are indented for clarity, as shown in the preceding code. Xcode will help impose
this convention, but the truth is that Swift doesn’t care, and layouts like this are legal
(and are sometimes more convenient):
class Dog { func bark() { print("woof") }}
Swift is a compiled language. This means that your code must build — passing
through the compiler and being turned from text into some lower-level form that a
computer can understand — before it can run and actually do the things it says to do.
The Swift compiler is very strict; in the course of writing a program, you will often try
to build and run, only to discover that you can’t even build in the first place, because
the compiler will flag some error, which you will have to fix if you want the code to
run. Less often, the compiler will let you off with a warning; the code can run, but in
general you should take warnings seriously and fix whatever they are telling you
about. The strictness of the compiler is one of Swift’s greatest strengths, and provides
your code with a large measure of audited correctness even before it ever runs.
The Swift compiler’s error and warning messages, however, range from the insightful
to the obtuse to the downright misleading. You will often know that something is
wrong with a line of code, but the Swift compiler will not be telling you clearly exactly
what is wrong or even where in the line to focus your attention. My advice in these
situations is to pull the line apart into several lines of simpler code until you reach a
point where you can guess what the issue is. Try to love the compiler despite the occa‐
sional unhelpful nature of its messages. Remember, it knows more than you do, even
if it is sometimes rather inarticulate about its knowledge.
But it is surprising to find that 1 can be followed by a dot and a message. This is legal
and meaningful in Swift (don’t worry about what it actually means):
let s = 1.description
But we can go further. Return to that innocent-looking 1 + 2 from our earlier code.
It turns out that this is actually a kind of syntactic trickery, a convenient way of
expressing and hiding what’s really going on. Just as 1 is actually an object, + is
actually a message; but it’s a message with special syntax (operator syntax). In Swift,
every noun is an object, and every verb is a message.
Perhaps the ultimate acid test for whether something is an object in Swift is whether
you can modify it. An object type can be extended in Swift, meaning that you can
define your own messages on that type. For example, you can’t normally send the say-
Hello message to a number. But you can change a number type so that you can:
extension Int {
func sayHello() {
print("Hello, I'm \(self)")
}
}
1.sayHello() // outputs: "Hello, I'm 1"
Everything Is an Object? | 5
Another Random Scribd Document
with Unrelated Content
YHDEKSÄSSEITSEMÄTTÄ LUKU
Vihdoinkin!
Arthur oli vielä liian heikko, jotta hänen kanssansa olisi voinut
puhua mistään levottomuutta herättävistä asioista, ja hänen
paranemisensa riippui suuresti siitä, että hän heikkoudessaan sai
nauttia rauhasta; sentähden Pikku Dorritin ainoana turvana tänä
raskaana aikana oli mr Meagles, joka oli yhä ulkomailla, mutta Pikku
Dorrit oli kirjoittanut hänelle hänen tyttärensä välityksellä heti
nähtyään Arthurin Marshalseassa ja sitten aina uskonut hänelle
levottomuutensa ja varsinkin erään huolestuttavan asian. Tästä
riippui, että mr Meagles yhä viipyi ulkomailla eikä palannut kotiin
tuomaan lohdutusta Marshalseaan.
Toivomatta, että mr Meagles tai kukaan muu oli voinut hyvin, miss
Wade kysyi, mikä tuotti hänelle kunnian tavata mr Meaglesiä taas.
Tällä välin vieras katseli ympärillensä huoneessa, huomaamatta
missään
lippaan tapaista.
»Ei.»
Vankilan rajoitettu ala vaikutti mrs Meaglesiin niin, että hän alkoi
itkeä, ja mr Meaglesiin niin, että hän alkoi läähättää ja haukkoa
ilmaa. Hän käveli edestakaisin huoneessa läähättäen ja pahentaen
asiaa hermostuneesti löyhyttelemällä kasvojaan nenäliinalla.
Kääntyessään aukenevaan oveen päin hän huudahti:
»Sinä näit tämän nuoren naisen, joka äsken juuri oli täällä — tuon
pienen, tyynen, hennon olennon, joka kävelee tuolla, Tatty. Katso,
ihmiset väistyvät hänen tieltänsä päästääkseen hänet ohitseen.
Miehet — katsos noita köyhiä ryysyistä olentoja — nostavat
kohteliaasti lakkiansa hänelle, ja nyt hän häviää tuon oven taakse.
Sinä näet hänet, Tattycoram?»
Loppu
Kun ääni vaikeni, pani hän käden silmillensä jupisten, että valo
huikaisi niitä.
»Te olette ollut täällä monen monta kertaa, vaikken ole nähnyt
teitä,
Pikku Dorrit?»
»Hyvin usein?»
»Jotenkin usein.»
»Joka päivä?»
Arthur olisi voinut päästää pienen käden irti, suudeltuaan sitä taas
lämpimästi, ellei se pehmeästi pysyen paikallaan olisi näyttänyt
pyytävän, että sitä edelleen pidettäisiin. Hän otti sen molempien
käsiensä väliin, ja se jäi hiljaa lepäämään hänen rinnalleen.
»Oikein reipas.»
»En ikinä!»
*****
Koska mr F:n täti kesti kuin luja linnoitus ja Flora oli virkistyksen
tarpeessa, lähetettiin sananviejä ravintolaan noutamaan
ennenmainittua pikaria, joka myöhemmin uudelleen täytettiin.
Pikarin sisällön, sanomalehden ja valiopiirakoiden avulla kesti Flora
tämän odotusajan varsin hyväntuulisena, vaikka hän tosin silloin
tällöin joutui ymmälle typerän huhun aiheuttamien seurausten
tähden: ympäristössä kerrottiin herkkäuskoisten lasten keskuudessa,
että muuan vanha rouva oli myynyt itsensä kahvilaan
piirakkatäytteeksi ja että hän nyt istui kahvilan vierashuoneessa
kieltäytyen täyttämästä sopimusta. Tämä juttu houkutteli niin suuren
joukon sekä tyttöjä että poikia paikalle, että se hämärän tullessa
haittasi liikettä siinä määrin, että kahvilan isäntä varsin jyrkästi vaati
mr F:n tätiä poisvietäväksi. Ajurin vaunut tuotiin siis ovelle ja
isännän ja Floran yhteisin ponnistuksin saatiin mr F:n täti
houkutelluksi niihin; tosin hän vielä pisti päänsä ikkunasta ja vaati
»häntä» tuotavaksi paikalle ennenmainittua tarkoitusta varten. Koska
huomattiin tämän ihmeteltävän johdonmukaisen naisen tässä
tilaisuudessa luovan murhaavia silmäyksiä Marshalseahan päin, on
otaksuttu hänen tarkoittaneen uhkillaan Arthur Clennamia. Tämä on
kuitenkin pelkkä otaksuma; kuka se henkilö oli, joka mr F:n tädin
tyydytykseksi olisi ollut tuotava paikalle, mutta jota ei milloinkaan
tuotu, se ei ikinä selvinne.
*****
»Miksei?»
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com