100% found this document useful (2 votes)
42 views

[Ebooks PDF] download Asynchronous Programming with SwiftUI and Combine: Functional Programming to Build UIs on Apple Platforms 1st Edition Peter Friese full chapters

SwiftUI

Uploaded by

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

[Ebooks PDF] download Asynchronous Programming with SwiftUI and Combine: Functional Programming to Build UIs on Apple Platforms 1st Edition Peter Friese full chapters

SwiftUI

Uploaded by

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

Download the Full Version of ebook for Fast Typing at ebookmass.

com

Asynchronous Programming with SwiftUI and Combine:


Functional Programming to Build UIs on Apple
Platforms 1st Edition Peter Friese

https://ebookmass.com/product/asynchronous-programming-with-
swiftui-and-combine-functional-programming-to-build-uis-on-
apple-platforms-1st-edition-peter-friese/

OR CLICK BUTTON

DOWNLOAD NOW

Download More ebook Instantly Today - Get Yours Now at ebookmass.com


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

Asynchronous Programming with SwiftUI and Combine 1st


Edition Peter Friese

https://ebookmass.com/product/asynchronous-programming-with-swiftui-
and-combine-1st-edition-peter-friese/

ebookmass.com

Mastering Functional Programming with Python Brett


Neutreon

https://ebookmass.com/product/mastering-functional-programming-with-
python-brett-neutreon/

ebookmass.com

Asynchronous Programming in Rust 1st Edition Carl Fredrik


Samson

https://ebookmass.com/product/asynchronous-programming-in-rust-1st-
edition-carl-fredrik-samson/

ebookmass.com

Modern Concurrency on Apple Platforms: Using async/await


with Swift 1st Edition Andrés Ibañez Kautsch

https://ebookmass.com/product/modern-concurrency-on-apple-platforms-
using-async-await-with-swift-1st-edition-andres-ibanez-kautsch/

ebookmass.com
Simple and Efficient Programming with C#: Skills to Build
Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar/
ebookmass.com

Simple and Efficient Programming with C# : Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar-2/
ebookmass.com

Introducing ReScript: Functional Programming for Web


Applications 1st Edition Danny Yang

https://ebookmass.com/product/introducing-rescript-functional-
programming-for-web-applications-1st-edition-danny-yang/

ebookmass.com

An Introduction to Parallel Programming. Second Edition


Peter S. Pacheco

https://ebookmass.com/product/an-introduction-to-parallel-programming-
second-edition-peter-s-pacheco/

ebookmass.com

Functional Programming in R 4: Advanced Statistical


Programming for Data Science, Analysis, and Finance Thomas
Mailund
https://ebookmass.com/product/functional-programming-in-r-4-advanced-
statistical-programming-for-data-science-analysis-and-finance-thomas-
mailund/
ebookmass.com
Asynchronous
Programming
with SwiftUI and
Combine
Functional Programming to
Build UIs on Apple Platforms

Peter Friese
Asynchronous
Programming with
SwiftUI and Combine
Functional Programming to
Build UIs on Apple Platforms

Peter Friese
Asynchronous Programming with SwiftUI and Combine: Functional
Programming to Build UIs on Apple Platforms
Peter Friese
Hamburg, Germany

ISBN-13 (pbk): 978-1-4842-8571-8 ISBN-13 (electronic): 978-1-4842-8572-5


https://doi.org/10.1007/978-1-4842-8572-5

Copyright © 2023 by Peter Friese


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Susan McDermott
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY
Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and
the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on the Github repository: https://github.com/Apress/Asynchronous-
Programming-with-SwiftUI-and-Combine. For more detailed information, please visit
http://www.apress.com/source-code.
Printed on acid-free paper
For Anne
Table of Contents
About the Author��������������������������������������������������������������������������������xv

Foreword������������������������������������������������������������������������������������������xvii

Preface����������������������������������������������������������������������������������������������xix

Acknowledgments�����������������������������������������������������������������������������xxi

About This Book������������������������������������������������������������������������������xxiii

Part 1�������������������������������������������������������������������������������������������1
Chapter 1: SwiftUI: A New Beginning���������������������������������������������������3
Why a New UI Framework?�����������������������������������������������������������������������������������5
SwiftUI Principles��������������������������������������������������������������������������������������������������7
Declarative vs. Imperative�������������������������������������������������������������������������������7
State Management������������������������������������������������������������������������������������������8
Composition over Inheritance��������������������������������������������������������������������������9
Everything Is a View—Except That It Isn’t�����������������������������������������������������10
UIs Are a Function of Their State�������������������������������������������������������������������10
A Quick Tour of SwiftUI����������������������������������������������������������������������������������������11
Prerequisites�������������������������������������������������������������������������������������������������11
Creating a New SwiftUI App��������������������������������������������������������������������������11
Adding Some Interaction to Your App������������������������������������������������������������19

v
Table of Contents

Using SwiftUI’s State Management to Keep UI and Model in Sync���������������25


Exercises�������������������������������������������������������������������������������������������������������������31
Summary������������������������������������������������������������������������������������������������������������31

Chapter 2: Getting Started with SwiftUI���������������������������������������������33


What We’re Going to Build�����������������������������������������������������������������������������������34
Composing a View for Displaying a Book������������������������������������������������������������36
Build the View with Static Data���������������������������������������������������������������������������40
Using the Preview to Make Sure Our View Works As Intended���������������������������51
Displaying a List of Books�����������������������������������������������������������������������������������53
Setting Up Data Binding��������������������������������������������������������������������������������������56
Adjusting the Preview Canvas�����������������������������������������������������������������������������59
Making the Code Reusable���������������������������������������������������������������������������������60
Refactoring the Code Using Extract Subview������������������������������������������������60
Renaming ContentView���������������������������������������������������������������������������������64
Keep Complexity in Check�����������������������������������������������������������������������������65
Views and View Modifiers�����������������������������������������������������������������������������������65
Exercises�������������������������������������������������������������������������������������������������������������66
Tips and Tricks����������������������������������������������������������������������������������������������������66
Summary������������������������������������������������������������������������������������������������������������67

Chapter 3: SwiftUI Building Blocks�����������������������������������������������������69


Views������������������������������������������������������������������������������������������������������������������70
User Interface Views��������������������������������������������������������������������������������������74
Container Views���������������������������������������������������������������������������������������������78
Layout Behavior���������������������������������������������������������������������������������������������79
Views Are Just Descriptions of the UI������������������������������������������������������������80
View Modifiers����������������������������������������������������������������������������������������������������83
Configuring Views������������������������������������������������������������������������������������������84

vi
Table of Contents

Applying View Modifiers to Child Views���������������������������������������������������������87


Using View Modifiers to Register Action Handlers�����������������������������������������89
Summary������������������������������������������������������������������������������������������������������������92

Chapter 4: State Management������������������������������������������������������������93


Managing State in SwiftUI����������������������������������������������������������������������������������94
Binding Value Types��������������������������������������������������������������������������������������������95
Binding Objects���������������������������������������������������������������������������������������������������98
ObservableObject������������������������������������������������������������������������������������������������99
@StateObject������������������������������������������������������������������������������������������������������99
When to Use������������������������������������������������������������������������������������������������101
@ObservedObject���������������������������������������������������������������������������������������������101
When to Use������������������������������������������������������������������������������������������������103
@EnvironmentObject����������������������������������������������������������������������������������������103
When to Use������������������������������������������������������������������������������������������������106
Summary����������������������������������������������������������������������������������������������������������106

Chapter 5: Displaying Data in Lists���������������������������������������������������107


Getting Started with Lists in SwiftUI�����������������������������������������������������������������107
Using Other SwiftUI Views Inside List Rows������������������������������������������������109
Building Custom List Rows��������������������������������������������������������������������������111
More Complex List Rows�����������������������������������������������������������������������������114
Dynamic Lists����������������������������������������������������������������������������������������������������117
Displaying a List of Elements����������������������������������������������������������������������117
Using List Bindings to Allow Modifying List Items���������������������������������������121
Asynchronously Fetching Data��������������������������������������������������������������������123
Pull-to-Refresh��������������������������������������������������������������������������������������������126
Searching����������������������������������������������������������������������������������������������������130

vii
Table of Contents

Styling���������������������������������������������������������������������������������������������������������������134
List Styles����������������������������������������������������������������������������������������������������135
Headers and Footers�����������������������������������������������������������������������������������137
List Cells������������������������������������������������������������������������������������������������������139
Separators���������������������������������������������������������������������������������������������������140
Actions��������������������������������������������������������������������������������������������������������������143
Swipe-to-Delete������������������������������������������������������������������������������������������144
Moving and Deleting Items Using EditMode������������������������������������������������145
Swipe Actions����������������������������������������������������������������������������������������������147
Managing Focus in Lists�����������������������������������������������������������������������������������154
How to Manage Focus in SwiftUI�����������������������������������������������������������������154
How to Manage Focus in Lists���������������������������������������������������������������������156
Handling the Enter Key��������������������������������������������������������������������������������158
What About MVVM?�������������������������������������������������������������������������������������159
Eliminating Empty Elements������������������������������������������������������������������������163
Summary����������������������������������������������������������������������������������������������������������165

Chapter 6: Building Input Forms�������������������������������������������������������167


Building Simple Forms��������������������������������������������������������������������������������������168
Showing Data in a Form������������������������������������������������������������������������������������179
Make It Editable������������������������������������������������������������������������������������������������182
Drill-Down Navigation���������������������������������������������������������������������������������������184
Input Validation�������������������������������������������������������������������������������������������������191
Using .onChange(of:)�����������������������������������������������������������������������������������192
Using a View Model to Handle Form Validation�������������������������������������������193
Synchronizing a Local Source of Truth with the Global Source of
Truth by Using @Binding and @ObservableObject��������������������������������������196
Using Combine to Perform Form Validation�������������������������������������������������202
Summary����������������������������������������������������������������������������������������������������������204

viii
Table of Contents

Part 2���������������������������������������������������������������������������������������205
Chapter 7: Getting Started with Combine�����������������������������������������207
What Is Functional Reactive Programming?�����������������������������������������������������207
Publishers���������������������������������������������������������������������������������������������������������209
Subscribers�������������������������������������������������������������������������������������������������������211
Operators����������������������������������������������������������������������������������������������������������213
Composing Operators���������������������������������������������������������������������������������������215
Combining Publishers���������������������������������������������������������������������������������������220
Summary����������������������������������������������������������������������������������������������������������223

Chapter 8: Driving UI State with Combine����������������������������������������225


Input Validation Using Combine������������������������������������������������������������������������226
The Sign-Up Form View�������������������������������������������������������������������������������227
The View Model�������������������������������������������������������������������������������������������229
Validating the Username�����������������������������������������������������������������������������232
Displaying Validation Messages������������������������������������������������������������������234
Encapsulating Combine Pipelines in Computed Properties�������������������������236
Validating the Password������������������������������������������������������������������������������238
Putting It All Together����������������������������������������������������������������������������������241
Exercises�����������������������������������������������������������������������������������������������������������243
Summary����������������������������������������������������������������������������������������������������������244

Chapter 9: Networking with Combine�����������������������������������������������247


Fetching Data Using URLSession����������������������������������������������������������������������248
Using Combine to Fetch Data����������������������������������������������������������������������������252
Destructuring Tuples Using Key Paths���������������������������������������������������������254
Mapping Data����������������������������������������������������������������������������������������������254
Fetching Data Using Combine, Simplified����������������������������������������������������255

ix
Table of Contents

Connecting to the UI������������������������������������������������������������������������������������������256


Handling Multithreading������������������������������������������������������������������������������������262
Optimizing Network Access������������������������������������������������������������������������������263
Finding the Root Cause�������������������������������������������������������������������������������264
Using the share Operator to Share a Publisher�������������������������������������������266
Using debounce to Further Optimize the UX������������������������������������������������269
Using removeDuplicates to Avoid Sending the Same Request Twice����������270
Bringing It All Together��������������������������������������������������������������������������������������271
Exercises�����������������������������������������������������������������������������������������������������������273
Summary����������������������������������������������������������������������������������������������������������274

Chapter 10: Error Handling in Combine��������������������������������������������275


Error Handling Strategies����������������������������������������������������������������������������������276
Ignoring the Error����������������������������������������������������������������������������������������276
Retrying (with Exponential Backoff)������������������������������������������������������������276
Showing an Error Message�������������������������������������������������������������������������277
Replacing the Entire View with an Error View���������������������������������������������277
Showing an Inline Error Message����������������������������������������������������������������278
Typical Error Conditions and How to Handle Them�������������������������������������������278
Implementing a Fallible Network API�����������������������������������������������������������279
Calling the API and Handling Errors�������������������������������������������������������������282
Handling Device/Network Offline Errors������������������������������������������������������286
Handling Validation Errors���������������������������������������������������������������������������289
Handling Response Parsing Errors��������������������������������������������������������������293
Handling Internal Server Errors�������������������������������������������������������������������298
Summary����������������������������������������������������������������������������������������������������������305

x
Table of Contents

Chapter 11: Implementing Custom Combine Operators�������������������307


What Is a Combine Operator?���������������������������������������������������������������������������307
Implementing Custom Operators����������������������������������������������������������������������309
Implementing a Retry Operator with a Delay����������������������������������������������������311
Conditionally Retrying���������������������������������������������������������������������������������������313
Implementing a Retry Operator for Exponential Backoff�����������������������������������314
Summary����������������������������������������������������������������������������������������������������������316

Chapter 12: Wrapping Existing APIs in Combine������������������������������317


A Case Study�����������������������������������������������������������������������������������������������������317
Using Combine to Access Firestore������������������������������������������������������������������321
Using View Models and Published Properties���������������������������������������������322
Using Combine to Wrap APIs�����������������������������������������������������������������������325
Creating Your Own Publishers���������������������������������������������������������������������������327
Using PassthroughSubject to Wrap Snapshot Listeners������������������������������328
Using Future to Implement One-Time Fetching from Firestore�������������������332
Summary����������������������������������������������������������������������������������������������������������335

Chapter 13: Combine Schedulers and SwiftUI����������������������������������337


What Is a Scheduler������������������������������������������������������������������������������������������338
Types of Schedulers������������������������������������������������������������������������������������������340
Default Behavior�����������������������������������������������������������������������������������������������341
Switching Schedulers���������������������������������������������������������������������������������������344
Controlling Upstream Publishers Using subscribe(on:)�������������������������������346
Controlling Downstream Subscribers Using receive(on:)����������������������������349
Other Operators That Influence Scheduling�������������������������������������������������351
Performing Asynchronous Work������������������������������������������������������������������������353

xi
Table of Contents

Integrating with Other APIs�������������������������������������������������������������������������������354


URLSession��������������������������������������������������������������������������������������������������355
Firebase�������������������������������������������������������������������������������������������������������356
Summary����������������������������������������������������������������������������������������������������������358

Part 3���������������������������������������������������������������������������������������361
Chapter 14: Getting Started with async/await���������������������������������363
Synchronous Programming with Functions������������������������������������������������������367
Asynchronous Programming with Closures������������������������������������������������������371
Asynchronous Programming with async/await������������������������������������������������377
Defining and Calling Asynchronous Functions��������������������������������������������377
Calling Asynchronous Functions in Parallel�������������������������������������������������381
Summary����������������������������������������������������������������������������������������������������������383

Chapter 15: Using async/await in SwiftUI����������������������������������������385


Fetching Data Asynchronously Using URLSession��������������������������������������������386
Calling Asynchronous Code�������������������������������������������������������������������������������387
The Task View Modifier�������������������������������������������������������������������������������������388
Calling Asynchronous Code When the User Taps a Button��������������������������������390
Using Pull-to-Refresh to Update Views Asynchronously�����������������������������������390
Searchable Views and async/await������������������������������������������������������������������391
Updating the UI from the Main Thread��������������������������������������������������������������394
Summary����������������������������������������������������������������������������������������������������������402

Chapter 16: Bringing It All Together: SwiftUI, async/await, and


Combine������������������������������������������������������������������������405
Fetching Data Using Combine���������������������������������������������������������������������������406
Fetching Data Using async/await����������������������������������������������������������������������407
Is This the End of Combine?������������������������������������������������������������������������������409

xii
Table of Contents

Connecting the UI…������������������������������������������������������������������������������������������410


…to a Combine Pipeline�����������������������������������������������������������������������������������410
…to an async/await Method����������������������������������������������������������������������������413
Calling Asynchronous Code from Combine�������������������������������������������������������415
Summary����������������������������������������������������������������������������������������������������������420

Index�������������������������������������������������������������������������������������������������423

xiii
About the Author
Peter Friese is a software engineer with over
30 years of experience in building software for
a wide range of platforms—from Windows,
J2EE, the Web, Android, to iOS and the Mac. He
works as a Senior Developer Advocate on the
Firebase team at Google, where he is in charge
of making sure iOS developer have a great
experience using the Firebase SDK on iOS and
Apple’s other platforms.
Peter writes about SwiftUI, Swift, and Firebase development on his
blog, peterfriese.dev, and can be found on Twitter as @peterfriese.

xv
Foreword
I’ve been developing iOS apps for a while and started learning SwiftUI
almost as soon as it was released back in 2019. I remember that I couldn’t
wait to start using it because it just seemed so much more intuitive for me
than UIKit.
There wasn’t much SwiftUI documentation at first and those of us who
jumped straight in had to figure out a lot of things for ourselves. So I started
sharing what I learned while building apps with SwiftUI on a blog.
Just a few months later, the SwiftUI team at Apple reached out to me to
join them in working on the framework. It was an invaluable experience
and it gave me a great perspective on the inner workings of SwiftUI and
the decisions behind the APIs. Sure, SwiftUI is not perfect and still needs
time to mature, but it’s already making many developers happier and more
excited about building apps for Apple platforms. A lot of thought goes into
making SwiftUI APIs as simple and as streamlined as they are, so that we
can get the right behavior for the platform by default.
I left Apple in April 2022 and joined Nil Coalescing as a cofounder and
a software engineer. Though I’m a little sad that I don’t get to contribute
to the SwiftUI framework directly anymore, I’m really happy that I’m
now able to use the APIs I helped to develop and to share my SwiftUI
knowledge with other iOS developers.
Seeing how much Apple is betting on SwiftUI by introducing new
frameworks that require using it like WidgetKit and Swift Charts, I believe
it has a great potential. It’s also nice to see how many more developers are
starting to use SwiftUI and how much more great SwiftUI-related content is
now available both from Apple and from the community.

xvii
Discovering Diverse Content Through
Random Scribd Documents
Such as will join their profit with their pleasure,
And come to feed their understanding parts;—
For these I'll prodigally spend myself,
And speak away my spirit into air;
For these I'll melt my brain into invention,
Coin new conceits, and hang my richest words
As polished jewels in their bounteous ears.5

5 BEN JONSON.

Such readers, they who to their learning add knowledge, and to their
knowledge wisdom and to their wisdom benevolence, will say to me

ὦ καλὰ λέγων, πολὺ δ᾽ ἄμεινον᾽ ἔτι τῶν λόγων


ἐργασάμεν᾽, εἴθ᾽ ἐπέλ—
θοις ἅπαντά μοι σαφῶς·
ὡς ἐγώ μοι δοκῶ
κἂν μακρὰν ὁδὸν διελθεῖν ὥς᾽ ἀκοῦσαι.
πρὸς τάδ᾽ ὦ βέλτιστε θαῤῥήσας λέγ᾽, ὡς ἃ—
παντες ἡδόμεσθά σοι.6

But such readers are very few. Walter Landor said that if ten such
persons should approve his writings, he would call for a division and
count a majority. To please them is to obtain an earnest of enduring
fame; for which, if it be worth any thing, no price can be too great.
But for the aggregate any thing is good enough. Yes my Public, Mr.
Hume's arithmetic and Mr. Brougham's logic, Lord Castlereagh's
syntax, Mr. Irving's religion and Mr. Carlisle's irreligion, the politics of
the Edinburgh Review and the criticism of the Quarterly, Thames
water, Brewer's beer, Spanish loans, old jokes, new constitutions,
Irish eloquence, Scotch metaphysics, Tom and Jerry, Zimmerman on
Solitude, Chancery Equity and Old Bailey Law, Parliamentary wit, the
patriotism of a Whig Borough-monger, and the consistency of a
British cabinet; Et s'il y a encore quelque chose à dire, je le tiens
pour dit;—
6 ARISTOPHANES.

Yes my Public,

Nor would I you should look for other looks,


Gesture, or compliment from me.7

7 BEN JONSON.

Minus dico quam vellem, et verba omninò frigidiora hæc quam ut


satis exprimant quod concipio:8 these and any thing worse than
these,—if worse than what is worst can be imagined, will do for you.
If there be any thing in infinite possibility more worthless than these,
more floccical-naucical, nihilish-pilish, assisal-teruncial, more good
for nothing than good for nothingness itself, it is good enough for
you.
8 PICUS MIRANDULA.

INTERCHAPTER XXII.

VARIETY OF STILES.

Qualis vir, talis oratio.


ERASMI ADAGIA.
Authors are often classed, like painters, according to the school, in
which they have been trained, or to which they have attached
themselves. But it is not so easy to ascertain this in literature as it is
in painting; and if some of the critics who have thus endeavoured to
class them, were sent to school themselves and there whipt into a
little more learning, so many silly classifications of this kind would
not mislead those readers who suppose in the simplicity of their own
good faith, that no man presumes to write upon a subject which he
does not understand.

Stiles may with more accuracy be classed, and for this purpose
metals might be used in literature as they are in heraldry. We might
speak of the golden stile, the silver, the iron, the leaden, the
pinchbeck and the bronze.

Others there are which cannot be brought under any of these


appellations. There is the Cyclopean stile, of which Johnson is the
great example; the sparkling, or micacious, possessed by Hazlitt,
and much affected in Reviews and Magazines; the oleaginous, in
which Mr. Charles Butler bears the palm, or more appropriately the
olive branch: the fulminating—which is Walter Landor's, whose
conversation has been compared to thunder and lightning; the
impenetrable—which is sometimes used by Mr. Coleridge; and the
Jeremy-Benthamite, which cannot with propriety be distinguished by
any other name than one derived from its unparellelled and
unparallellable author.

Ex stilo, says Erasmus, perpendimus ingenium cujusque, omnemque


mentis habitum ex ipsâ dictionis ratione conjectamus. Est enim
tumidi, stilus turgidus; abjecti, humilis, exanguis; asperi, scaber;
amarulenti, tristis ac maledicus; deliciis affluentis, picturatus ac
dissolutus; Breviter, omne vitæ simulacrum, omnis animi vis, in
oratione perinde ut in speculo repræsentatur, ac vel intima pectoris,
arcanis quibusdam vestigiis, deprehenduntur.
There is the lean stile, of which Nathaniel Lardner, and William Coxe
may be held up as examples; and there is the larded one,
exemplified in Bishop Andrews, and in Burton, the Anatomist of
Melancholy; Jeremy Taylor's is both a flowery and a fruitful stile:
Harvey the Meditationist's a weedy one. There are the hard and dry;
the weak and watery; the manly and the womanly; the juvenile and
the anile; the round and the pointed; the flashy and the fiery; the
lucid and the opaque; the luminous and the tenebrous; the
continuous and the disjointed. The washy and the slap-dash are
both much in vogue, especially in magazines and reviews; so are the
barbed and the venomed. The High-Slang stile is exhibited in the
Court Journal and in Mr. Colburn's novels; the Low Slang in Tom and
Jerry, Bell's Life in London, and most Magazines, those especially
which are of most pretensions.

The flatulent stile, the feverish, the aguish, and the atrabilious are all
as common as the diseases of body from which they take their
name, and of mind in which they originate; and not less common
than either is the dyspeptic stile, proceeding from a weakness in the
digestive faculty.

Learned, or if not learned, Dear Reader, I had much to say of stile,


but the under written passage from that beautiful book, Xenophon's
Memorabilia Socratis, has induced me, as the Latins say, stilum
vertere, and to erase a paragraph written with ink in which the gall
predominated.

Ἐγὼ δ᾽ οὖν καὶ αὐτὸς, ὦ Αντιφῶν, ὥσπερ ἄλλός τις ἢ ἵππῳ ἀγαθῷ ἢ
κυνὶ ἢ ὂρνιθι ἥδεται, οὕτω καὶ ἒτι μᾶλλον ἥδομαι τοῖς φίλοις ἀγαθοῖς·
καὶ, ἐάν τι σχῶ ἀγαθὸν διδάσκω, καὶ ἄλλοις σύνιστημι, παρ᾽ ὧν ἂν
ἡγῶμαι ὠφελήσεσθαί τι αὐτοὺς εἰς ἀρετήν᾽ καὶ, τοὺς θησαυροὺς τῶν
πάλι σοφῶν ἀνδρῶν, οὕς ἐκεῖνοι κατέλιπον ἐν βιβλίοις γράφεντες,
ἀνελίττων κοινῆ σὺν τοῖς φίλοις διέρχομαι· καὶ ἄν τι ὁρῶμεν ἀγαθὸν,
ἐκλεγόμεθα, καὶ μέγα νομίζομεν κέρδος, ἐὰν ἀλλήλοις ὠφέλιμοι
γιγνώμεθα.
INTERCHAPTER XXIII.

A LITTLE ADVICE BESTOWED UPON THE SCORNFUL READER IN A SHORT INTERCHAPTER.

No man is so foolish, but may give another good counsel sometimes; and no man is
so wise, but may easily err, if he will take no other counsel but his own.

BEN JONSON.

I will now bestow a little advice upon the scornful reader.

And who, the Devil, are you exclaims that reader, who are
impertinent enough to offer your advice, and fool enough to suppose
that I shall listen to it?

Whatever your opinion may be, Sir, concerning an Evil Principle,


whether you hold with the thorough-paced Liberals, that there is no
Principle at all, (and in one sense, exemplify this in your own
conduct,) or with the Unitarians that there is no Evil one; or whether
you incline to the Manichean scheme of Two Principles, which is said
to have its advocates,—in either case the diabolical expletive in your
speech is alike reprehensible: you deserve a reprimand for it; and
you are hereby reprimanded accordingly.—Having discharged this
duty, I answer your question in the words of Terence, with which I
doubt not you are acquainted, because they are to be found in the
Eton grammar: Homo sum, nihil humani à me alienum puto.
And what the Devil have the words of Terence to do with my query?

You are again reprimanded Sir. If it be a bad thing to have the Devil
at one's elbow, it cannot be a good one to have him at ones
tongue's end. The sentence is sufficiently applicable. It is a humane
thing to offer advice where it is wanted, and a very humane thing to
write and publish a book which is intended to be either useful or
delightful to those who read it.

A humane thing to write a book!—Martin of Galway's humanity is not


a better joke than that!

Martin of Galway's humanity is no joke, Sir. He has began a good


work, and will be remembered for it with that honour which is due to
all who have endeavoured to lessen the sum of suffering and
wickedness in this wicked world.

Answer me one question, Mr. Author, if you please. If your book is


intended to be either useful or delightful, why have you filled it with
such a parcel of nonsense?

What you are pleased to call by that name, Mr. Reader, may be
either sense or nonsense according to the understanding which it
meets with. Quicquid recipitur, recipitur in modum recipientis. Look
in the seventh Chapter of the second book of Esdras, and at the
twenty-fifth verse you will find the solution of your demand.

And do you suppose I shall take the trouble of looking into the Bible
to please the humour of such a fellow as you?

If you do not, Sir, there are others who will; and more good may
arise from looking into that book,—even upon such an occasion,—
than either they or I can anticipate.

And so, scornful reader, wishing thee a better mind, and an


enlightened understanding, I bid thee gladly and heartily farewell!
END OF VOL. VI.

W. Nicol, 60, Pall Mall.


*** END OF THE PROJECT GUTENBERG EBOOK THE DOCTOR, &C.,
VOL. 6 (OF 7) ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like