Full Learn Swift by Building Applications Explore Swift Programming Through iOS App Development 1st Edition Emil Atanasov Ebook All Chapters
Full Learn Swift by Building Applications Explore Swift Programming Through iOS App Development 1st Edition Emil Atanasov Ebook All Chapters
com
https://textbookfull.com/product/learn-swift-by-
building-applications-explore-swift-programming-
through-ios-app-development-1st-edition-emil-
atanasov/
https://textbookfull.com/product/learn-ios-11-programming-with-
swift-4-craig-clayton/
textbookfull.com
https://textbookfull.com/product/ios-13-programming-fundamentals-with-
swift-swift-xcode-and-cocoa-basics-1st-edition-matt-neuburg/
textbookfull.com
https://textbookfull.com/product/advanced-ios-app-architecture-first-
edition-real-world-app-architecture-in-swift-5-rene-cacheaux/
textbookfull.com
https://textbookfull.com/product/therapeutic-applications-of-
adenoviruses-1st-edition-philip-ng/
textbookfull.com
Dragons Savior 1st Edition Milly Taiden Taiden Milly
https://textbookfull.com/product/dragons-savior-1st-edition-milly-
taiden-taiden-milly/
textbookfull.com
https://textbookfull.com/product/atlas-and-anatomy-of-pet-mri-pet-ct-
and-spect-ct-1st-edition-e-edmund-kim/
textbookfull.com
https://textbookfull.com/product/ethics-and-decision-making-in-
counseling-and-psychotherapy-5th-robert-roco-cottone/
textbookfull.com
https://textbookfull.com/product/over-the-influence-the-harm-
reduction-guide-to-controlling-your-drug-and-alcohol-use-2nd-edition-
patt-denning/
textbookfull.com
https://textbookfull.com/product/oil-revenues-security-and-stability-
in-west-africa-vandy-kanyako/
textbookfull.com
Learn Swift by Building
Applications
&YQMPSF4XJGUQSPHSBNNJOHUISPVHIJ04BQQEFWFMPQNFOU
Emil Atanasov
BIRMINGHAM - MUMBAI
Learn Swift by Building Applications
Copyright a 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations
embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented.
However, the information contained in this book is sold without warranty, either express or implied. Neither the
author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to
have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy
of this information.
ISBN 978-1-78646-392-0
XXXQBDLUQVCDPN
NBQUJP
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.
At XXX1BDLU1VCDPN, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.
Contributors
I want to thank my wife Elena, my family, and my friends for being very supportive, really
patient, and super cool. Thank you for keeping me motivated through the endless work
days. I know that in your eyes I'm a bizarre geeky person, who is spending most of the
time in the digital world. I appreciate your understanding.
About the reviewer
Giordano Scalzo is a developer with 20 years of programming experience, since the days of
ZXSpectrum. He has worked in C++, Java, .Net, Ruby, Python, and in a ton of other
languages that he has forgotten the names of. After years of backend development, over the
past 5 years, Giordano has developed extensively for iOS, releasing more than 20
appsbapps that he wrote for clients, enterprise application, or on his own. Currently, he is
a contractor in London where, he delivers code for iOS through his company, Effective
Code Ltd, aiming at quality and reliability.
I`d like to thank my better half, Valentina, who lovingly supports me in everything I do:
without you, none of this would have been possible.
Thanks to my bright future, Mattia and Luca, for giving me lots of smiles and hugs when I
needed them.
Finally, my gratitude goes to my mum and dad, who gave me curiosity and the support to
follow my passions, which began one day when they bought me a ZXSpectrum.
AppDelegate 74
Application states 76
ViewController 77
Git 79
Summary 83
Chapter 4: Structures, Classes, and Inheritance 84
Structures and classes 84
Extensions 91
The deinit method 94
Type properties and functions 94
Adding custom data types to a playground 96
Inheritance 100
Base class 100
Class properties 103
Model-View-Controller (MVC) 104
Summary 108
Chapter 5: Adding Interactivity to Your First App 109
Storyboards 109
Visual components 111
Adding items to the storyboard 118
Linking the UI with the code 122
General discussion 138
Summary 139
Chapter 6: How to Use Data Structures, OOP, and Protocols 140
Primary collection types 140
Generics 141
Array 142
Set 144
Dictionary 148
How to choose the best collection type 150
List of items in a playground 151
UICollectionView 151
UICollectionViewCell 154
Reusing cells 157
Layouts 159
Table view in iOS app 163
Model list of cities 165
Displaying all cities 167
Adding search 172
Protocols 175
Protocols and inheritance 177
Summary 180
Chapter 7: Developing a Simple Weather App 181
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Preface
Learning Swift 4 by Building Applications is a book that teaches the basics of Swift in the
context of iOS. If you finish the book, you should be able to develop small-to-medium
mobile apps. You will know how to create the app UI in storyboard using Xcode, how to
load and display images fetched from the cloud, how to save and load information between
different sessions of the app, and how to share data between all users of the app using the
cloud.
$IBQUFS, Getting Familiar with Xcode and Playgrounds, presents the Xcodeba free IDE that
we will use when developing Swift. We shouldn't forget that Xcode is developed by Apple
and that the playgrounds are the perfect place for learning Swift step by step.
$IBQUFS, Creating a Minimal Mobile App, makes you examine the minimal mobile app and
its structure. This is the basis of every iOS mobile app written in Swift.
$IBQUFS, Structures, Classes, and Inheritance, covers the benefit of different data structures
and how easily we can model a real-world problems.
$IBQUFS, Adding Interactivity to Your First App, looks at the different ways to add
interactivity to an app or how to interact with the user in the app.
Preface
$IBQUFS, How to Use Data Structures, OOP, and Protocols, explores the data structures and
different techniques to incorporate them in our solutions.
$IBQUFS, Developing a Simple Weather App, focuses on how to build a real mobile app
starting from the UI and displaying static data.
$IBQUFS, Introducing CocoaPods and Project Dependencies, introduces the modern way of
rapid development using various dependency managers of Swift libraries.
$IBQUFS, Building an Instagram-Like App, builds an app from the idea step by step
starting with the design, defines the basic UI, and connects it with a real cloud service
providerbFirebase.
$IBQUFS, Instagram-Like App Continued, makes the app complete and functional so that it
can look like a working product, ready to be shared with users.
$IBQUFS, Contributing to an Open Source Project, takes you through the basics of
contributing to an open source project.
You need enough time and patience to go through the book and to experiment with the
code, which can be found on GitHub.
[2]
Preface
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
We also have other code bundles from our rich catalog of books and videos available
at IUUQTHJUIVCDPN1BDLU1VCMJTIJOH. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
$PEF*O5FYU: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "This code creates a place in the memory, called UFYU, where we store the
text, )FMMPXPSME."
[3]
Preface
When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
letOVNCFS
letEJWJTPS
letSFNBJOEFSOVNCFSEJWJTPSSFNBJOEFSJTBHBJOJOUFHFS
letRVPUJFOUOVNCFSEJWJTPSRVPUJFOUJTBHBJOJOUFHFS
Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
"Also, add an action to the Sign In With Email button."
Get in touch
Feedback from our readers is always welcome.
General feedback: Email GFFECBDL!QBDLUQVCDPN and mention the book title in the
subject of your message. If you have questions about any aspect of this book, please email
us at RVFTUJPOT!QBDLUQVCDPN.
[4]
Preface
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit XXXQBDLUQVCDPNTVCNJUFSSBUB, selecting your book,
clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at DPQZSJHIU!QBDLUQVCDPN with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
BVUIPSTQBDLUQVCDPN.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!
[5]
1
Swift Basics – Variables and
Functions
In this chapter, we will present the basics of the Swift language, starting from square one:
introducing the basic concepts. The code, which is part of the chapter, illustrates the topics
under discussion. In the next chapter, we will learn how to execute code samples in Xcode.
Let's begin with a brief history of Swift. This is a brand new programming language,
developed by Apple and announced in 2014. In 2016, Swift 3 was released as open source,
and this is the first major version, which enables people interested in Swift to develop the
language. This means only one thing: Swift will start spreading even faster, beyond Apple's
ecosystem. In this book, we will give examples of Swift, and we will discuss most of our
solutions related to iOS, but you should know that the knowledge here is applicable across
all places where Swift code is used.
Before diving into real code, let's define some basic concepts that we can use later in the
book.
What is a computer program or application (app)? Simply, we can think of an app as a set
of computer instructions that can be executed. Each app has a source code, written in a
language describing all actions that the program does. In our case, we will write mobile
(iOS) apps in Swift.
There are many low-level computer instructions, but Swift helps us to write without hassle,
without knowing much about the low-level organization. Now we will start with the basic
concept of variables.
Swift Basics – Variables and Functions Chapter 1
Variables
What is a variable? This is a place in the memory where we can store some data and use it
later in our program. A good example is if you want to take an action based on a user's
input, then the input should be stored somewhere on the device (computer). Usually, this
place is in the device's memory. To let our program know that we need such a place, we
have to express that. A WBS statement is used.
This code creates a place in the memory, called UFYU, where we store the text, )FMMP
XPSME. Later, we can use it to carry out some meaningful actions.
An advantage of a variable is that it can be changed later to contain a different value. Here,
we should be carefulbSwift is pretty strict about types (this will be discussed later), and,
thus, we can't mix different value types. There are strict rules that should be followed, and
we will get familiar with these soon. So, in our case, we can do the following to change the
text that is stored in our variable, named UFYU:
UFYU)FZ*U T4XJGU
[7]
Swift Basics – Variables and Functions Chapter 1
Now we know what a variable is and how to work with variables. Let's try to do some
calculations using variables, with stored integer values:
var GJWF
var GPVS
var TVNGPVS GJWF
In the preceding code, we have created three variables. The first two were initialized with
literal expressions, or simply with exact values. In the code, we can use complex
calculations, and the Swift compiler will handle this case easily as follows:
var GJWF
The last variable TVN is initialized with the value of the expression GPVS GJWF. To
calculate this expression, the compiler uses the values stored in the previously declared
variables (on the previous lines). The evaluation happens once the code is executed. What
does this mean: The evaluation happens once the code is executed? In short, if GPVS or GJWF
contain different values, then the TVN variable will reflect this. The code is working with the
names of the places in memory, but the actual result depends on the values stored there.
Create a place in the memory, which we will call GJWF, and store the value in it
Create a place in the memory, which we will call GPVS, and store the value in it
Create another place in the memory, called TVN, and store the value of the
expression of what's stored in GPVS plus what's stored in GJWF
Usually, we use variables to allocate places in memory, which we will modify in the
following code. But we don't always want to change the value of a variable once it is set.
Thus, to simplify it, there is a special word in Swift, MFU, which denotes a place in the
memory that won't be changed in the future. Its value is set initially and it can't be changed.
(This is slightly different when we are working with objects, but this will become clear later
in the book.)
[8]
Swift Basics – Variables and Functions Chapter 1
The following code defines a place in memory that won't be updated. If we try to update it,
then the Swift compiler will inform us that it is not possible. The value on the left is a
constant and we are trying to change it:
letIFMMP8PSME)FMMP8PSME
IFMMP8PSME)FMMP4XJGU8PSMEUIFDPNQJMFSJTDPNQMBJOJOH
Let's see how we can update our previous code snippets, once we know that there are WBS
and MFU keywords.
The first code with the UFYU variable should be the same, because we change the value of
the variable UFYU. The second code, with the sum of two integers, could be rewritten as
follows:
let GJWF
let GPVS
let TVNGPVS GJWF
A good practice is to keep using MFU whenever possible. The compiler gives us hints all the
time. Of course, it's possible to keep something stored in a variable instead of a constant
while developing, but if we want to squeeze out every single bit of performance, then we
should stick to the best practicebreplace all unmodified variables with constants.
Why do we gain performance when using MFU? The short answer is, the compiler knows
that this place in the memory will be used only for reading from operations, and it cuts all
the extra logic, which is needed to support modifications. The developers can reason locally
and don't need to foresee any future changes of this value, because it is immutable.
Now we are familiar with variables, it's the perfect time to introduce the concept of a type.
First, each variable has a type. The type defines the set of values which can be stored in a
variable. Each type uses a different amount of the device's memory. Based on the type, the
compiler knows how much space should be allocated when we declare a new variable.
In Swift, we define the type of a variable after the declaration of the variable itself. Our first
code would look like this:
var UFYU4USJOH)FMMP8PSME
[9]
Swift Basics – Variables and Functions Chapter 1
The Swift compiler is quite smart, and it infers the types based on the expressions on the
right side. There are many examples which could illustrate how smart it is. But we should
remember one: if the variable or constant is initialized, then we can simply omit the type.
Of course, explicitly pointing to the type will make the code easier for other developers to
understand. It's good to keep the same code style through all your code across every
project. For some projects, it could be better if the type is omitted; for some, it may be
worse.
Let's present all the basic types that Swift uses. The numbers are presented by several
different types, based on the precision which is needed. The largest type takes extra
memory, but it can store bigger values. The integer numbers can be stored in variables or
constants from the following types: *OU, *OU, *OU, *OU, *OU, 6*OU, 6*OU, and
6*OU. Floating-point numbers can be of the following types: 'MPBU, 'MPBU, 'MPBU,
and %PVCMF. We are already familiar with the 4USJOH type. It's used to store text in
computer memory. Later, the text can be manipulated and presented to the user in different
forms. The other quite popular data type is #PPM, which takes exactly two valuesbUSVF or
GBMTF. We will discuss the need of boolean expressions later in this chapter, once we get
familiar with conditional statements in Swift. We will define enumerable types and tuples.
These are specific types that we can define, compared to the other ones, which are already
defined for us.
Until now, we could declare variables or constants in one particular way. There are
advanced ways to do thisbone is to declare multiple variables on a single line, like this:
varBCTVN%PVCMF
We can specify a different type for each one, which gives us the freedom to declare
variables/constants in a single shot on the same line.
We can expand this even further by setting a default value, like in the following code:
varY%PVCMFC#PPMUSVF
[ 10 ]
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Swift Basics – Variables and Functions Chapter 1
Of course, Swift is smart enough, so the following code has the very same meaning:
varYCUSVF
This automatic process is called type inference and greatly reduces the unnecessary
boilerplate code which we would have to write.
Before diving into the details related to the different data types, we should know how to
add comments to our code. Comments are blocks of text which are part of the source code,
but they are removed when the source code is compiled.
The comment's role is to clarify the code. There are two types of comments that we can use
when we are developing a program in Swift. The first type is a single-row comment, which
starts with (double slash) and continues until the end of the row. Usually, developers
prefer to start this comment on a new row or to add it to the end of a line, presenting a
detail about the code, so it's easier for the reader to understand the encoded programming
logic. The other type is a block comment, which starts with (slash and asterisk) and ends
with (asterisk and slash). The comment can start anywhere, and continues until the
matching ending sequence.
This is something new, which simplifies the process when we are adding comments.
[ 11 ]
Swift Basics – Variables and Functions Chapter 1
Optional types
We are familiar with basic types and their forms, but now it's time to introduce the optional
type(s). This is a new concept, compared to what we have in Objective-C, which helps
developers to avoid common mistakes when they are working with data. To explain the
optional type(s), we should present the problem they are solving.
When we are developing a program, we can declare a variable, and we should set it an
initial value. Later in the code, we can use it. But this is not applicable in general. There
may be some cases when the default value is to have /07"-6&, or simply OJM. This means
that when we want to work with a variable which has /07"-6&, we should check that. But
if we forget the check, then while our app is executed, we can reach this strange state with
/07"-6&, and the app usually crashes. Also, the code which checks whether a variable
contains a value is reduced, and the programming style is concise.
To summarize: optionals enforce better programming style and improve the code checking
when the compiler does its job.
Now let's meet the optional types in the following code snippet:
varGJWF0S/PUIJOH*OU
XFXJMMEJTDVTTUIFJGTUBUFNFOUMBUFSJOUIJTDIBQUFS
JGletGJWFGJWF0S/PUIJOH\
QSJOU GJWF
^FMTF\
QSJOU 5IFSFJTOPWBMVF
^
GJWF0S/PUIJOHOJM
XFXJMMEJTDVTTUIFJGTUBUFNFOUMBUFSJOUIJTDIBQUFS
JGletGJWFGJWF0S/PUIJOH\
QSJOU GJWF
^FMTF\
QSJOU 5IFSFJTOPWBMVF
^
Every type we know so far has an optional version, if we can call it that. Later in the book,
you will understand the whole magic behind the optional types; namely, how they are
created. Here are some of those: 4USJOH, #PPM, %PVCMF, 'MPBU, and so on.
[ 12 ]
Swift Basics – Variables and Functions Chapter 1
Until now, we have learned how to store data, but we don't know what kind of actions we
can do with it. This is why we should get familiar with basic operations with the data. The
operations are denoted with operators such as , , , and . These operations work with
particular data types, and we have to do the conversion ourselves.
letIFZ)J
letHSFFUJOH4XJGUIFZ 4XJGUPQFSBUPS DPODBUFOBUFTTUSJOHT
Enumeration types
In Swift, we can define simple types which have limited possible different values. These
types are enumerations. We define them with the keyword FOVN. The following code is an
example of this:
FOVN"O&OVNFSBUJPO\
UIFWBMVFEFGJOJUJPOTHPFTIFSF
^
The code has three different enumeration cases. All cases may appear on a single line, such
as in the preceding code, or even one by one on a line.
We can meet the following notation, because Swift infers the missing part:
varJOQVU(BNF*OQVU%FWJDFNPVTF
MBUFSJOUIFDPEF
JOQVUKPZTUJDL
[ 13 ]
Swift Basics – Variables and Functions Chapter 1
[ 14 ]
Swift Basics – Variables and Functions Chapter 1
We know that the JG clause gives us huge freedom to shape the code that will be executed
(evaluated). An application may handle many different cases, but only the code that fulfills
the conditions encoded in our solution will be triggered.
Loops
Let's learn how to implement repetitive tasks. There are several ways to do that, using
different loops: XIJMF, GPSJO, and SFQFBUXIJMF. The most popular one is the
GPSJO loop. Here is what the basic form looks like:
let DPMMFDUJPO<>
GPSWBSJBCMFJODPMMFDUJPO\
EPTPNFBDUJPO
^
The code will be interpreted like this: the variable will be set to all possible values, which
are stored in the collection. If the collection is empty, then no code will be executed. If there
are some elements, then the body of the loop (the code in curly braces) will be executed for
each element of the collection. The variable loops through every single element and can be
used in code.
We need an example to illustrate this. Let's use the following code to print all numbers
from to , inclusive:
varTVN
GPSJOEFYJO\
TVN JOEFY
QSJOU JOEFY
^
QSJOU 4VN= TVN
TVNJTFRVBMUP
The sum of all numbers from to is stored in a separate variable and the code prints
every single number on a new line. The sequence defined with is converted to a
collection (we can think of it as an array), which is fueling the GPSJO loop.
[ 15 ]
Random documents with unrelated
content Scribd suggests to you:
L’aspirant Maréchal-Ferrant débute par être compagnon rouleur.
Aussitôt qu’il a quelque teinture du métier, il quitte son premier maître,
part, et va de ville en ville, s’arrêtant pour travailler au prix de dix-huit
à trente francs par mois. Grâce aux lois bienfaisantes du
compagnonnage, il est assuré d’un gîte en attendant de l’emploi. Un
compagnon rouleur entre dans Paris; est-il isolé, perdu, au milieu de
l’immense population? point. Il demande au premier passant qu’il
rencontre la rue Vieille-du-Temple; arrivé devant le no 97, il avise, au
centre de la façade de cette maison, un carré long peint en noir, sur
lequel se détachent en ronde bosse des fers dorés et la statue de saint
Éloi. Au-dessus est écrit en lettres raturées par le temps:
J’entends Javotte,
Portant sa hotte,
Crier: carotte,
Panais et chou-fleur.
Perçant et grêle,
Son cri se mêle
A la voix frêle
Du noir ramonneur.
Désaugiers.
Et quand même que je m’serais reposée une miette? J’ai les jambes
qui m’rentrent dans l’dos. Faut-il pas être comme le Juif-Errant?
LE SERGENT-DE-VILLE, brusquement.
LA MARCHANDE.
LE SERGENT-DE-VILLE.
LA MARCHANDE, exaspérée.
Le commissaire va en décider.
LA MARCHANDE, se débattant.
N’y a donc pas de justice en France? Grand mouchard, faut que
j’t’abîme le physique!
La main robuste du fonctionnaire municipal contient son adversaire
furieuse; il oppose un front impassible aux huées de la multitude. La
marchande des quatre-saisons est menée chez le commissaire, laissant
sur le pavé son bonnet et la moitié de ses légumes; elle passe sa
soirée dans ce séjour malsain vulgairement appelé violon, et voit
vendre, le lendemain, ses denrées au bénéfice du gouvernement,
auquel la cargaison entière rapporte la modique somme de 10
centimes.
Les vieilles marchandes des quatre-saisons sont plus rassises et
moins rebelles; presque toutes inscrites au nombre des indigents,
recevant des secours des bureaux de bienfaisance, elles sont
familiarisées avec la misère et la subordination. «Les sergents-de-ville
nous saisissent, disent-elles; ils font vendre nos pauvres légumes, et
donnent pour un sou ce qui nous en a coûté dix; mais que voulez-
vous? c’est leur métier, comme le nôtre est de vendre des légumes; il
faut obéir aux lois.»
Que de vertu dans cette résignation!
La vieille marchande des quatre-saisons a de vieux souvenirs de
choses qu’elle n’a jamais vues. Elle parle du pilori, qui fut démoli en
vertu de lettres-patentes du 16 septembre 1785, enregistrées en
parlement le 16 janvier 1786. Elle indique la place qu’il occupait près
des piliers de gauche de la Halle, dits Petits Piliers, ou Piliers d’Étaim.
Elle raconte comment il était percé de trous par où les banqueroutiers
frauduleux, qu’on exposait les jours de marché, passaient la tête et les
bras. Elle persiste à appeler le cimetière, la place au milieu de laquelle
s’élève la fontaine de Jean Goujon, quoique les charniers des
Innocents aient été détruits en 1787. Sa mémoire la reporte encore au
temps de Napoléon, qu’elle a vu, affirme-t-elle, venir plusieurs fois à la
Halle. «Il s’habillait en simple ouvrier, comme vous et moi; personne
ne le reconnaissait. Il entrait sans façon chez un marchand de vin: «Eh
bien, qu’il disait, êtes-vous content?—Non, Monsieur, que répondait le
marchand de vin; les contributions sont trop chères.—On les
diminuera, mon brave, que répliquait l’Empereur;» et il s’en allait en
donnant au marchand de vin une pièce de vingt francs. Le marchand
regardait l’empreinte, et disait: «C’est son portrait tout craché; et
d’ailleurs, n’y a qu’lui qui peut être si généreux: Vive l’Empereur!»
Alors, toute la Halle était en rumeur; tout le monde quittait son
ouvrage, et nous poussions des cris de vive l’Empereur! à être
entendus des quais aux boulevards. Ah! pourquoi qu’il s’est avisé
d’aller en Russie!»
Ces récits apocryphes prouvent l’embrouillement des idées de nos
marchandes, mais ils démontrent en même temps que quiconque
s’occupe un peu d’elles peut compter sur leur reconnaissance.
Les paysans des environs de Paris prennent rang parmi les
marchands et marchandes des quatre-saisons. Les vendeurs de fruits
au panier de Fontainebleau, Melun, Corbeil, Choisy-le-Roi, Villeneuve-
Saint-Georges, descendent la Seine, et débarquent leurs provisions au
bas du quai de la Tournelle, vis-à-vis l’île Saint-Louis. Il est interdit aux
pratiques d’aller au-devant d’eux pour acheter les fruits en gros et par
batelées. Défense non moins expresse d’exposer en vente des fruits
gâtés, de mettre au fond des paniers des fruits de qualité inférieure ou
des bouchons autres que ceux qui sont nécessaires à la conservation
des denrées. Les consommateurs seraient trop heureux si ces
prescriptions étaient accomplies seulement à moitié.
Toute la journée, d’autres habitants de la banlieue et des
faubourgs, traînant des banneaux, ou portant des paniers à la main,
sillonnent les rues, et nous assourdissent de leurs clameurs:
«Artichauts, les bons artichauts! la tendresse, la verderesse!
—Des fraises, des fraises!
—Qui veut la pêche au vin, la pêche au vin?
—Voyez les beaux œufs, Mesdames, les beaux œufs au quarteron!
—Ma belle botte d’asperges!
—Ach’tez les beaux melons!
—Mangez les pêches, buvez les pêches! à quatre pour un sou les
pêches! il n’y en aura pas pour tout le monde.
—Voyez les haricots verts; quatre sous la livre!
—Voyez les belles cerises; deux sous la livre!
—Les beaux champignons! les beaux champignons!
—Pois verts au boisseau! pois verts!
—A quatre sous la livre le beau raisin! à quatre sous la livre! Allons,
prenez-en connaissance; mettez-en un grain dans vot’ bouche.»
Dans la catégorie des marchandes des quatre-saisons, est comprise
aussi la bouquetière; non celle dont le magasin est orné de plantes
rares, de cactus et d’orangers, mais la bouquetière nomade, qui
débite, sur un plateau d’osier, des roses, des violettes et des œillets.
Pauvre revendeuse de fleurs, qui trafiquez d’une des plus
charmantes choses de la création, nous voudrions pouvoir dire de vous
que vous êtes aussi fraîche que vos bouquets; mais, hélas!....
Le Marchand de Coco.
X.
LE MARCHAND DE COCO.
[11] Je périssais.
[12] Un coup d’eau.
[13] Enfant.
[14] De l’argent.
[15] Idem.