Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

Build Mobile Apps with SwiftUI and

Firebase: Learn SwiftUI and Firebase by


Building Real-World Applications
Communicating with a Backend 1st
Edition Sullivan De Carli
Visit to download the full and correct content document:
https://ebookmass.com/product/build-mobile-apps-with-swiftui-and-firebase-learn-swif
tui-and-firebase-by-building-real-world-applications-communicating-with-a-backend-1
st-edition-sullivan-de-carli/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Pro iPhone Development with SwiftUI: Design and Manage


Top Quality Apps (4th Edition) Wallace Wang

https://ebookmass.com/product/pro-iphone-development-with-
swiftui-design-and-manage-top-quality-apps-4th-edition-wallace-
wang/

Asynchronous Programming with SwiftUI and Combine 1st


Edition Peter Friese

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

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/

Programming Kotlin Applications: Building Mobile and


Server-Side Applications With Kotlin Brett Mclaughlin

https://ebookmass.com/product/programming-kotlin-applications-
building-mobile-and-server-side-applications-with-kotlin-brett-
mclaughlin/
Beginning iPhone Development with SwiftUI: Exploring
the iOS SDK (7th Edition) Wallace Wang

https://ebookmass.com/product/beginning-iphone-development-with-
swiftui-exploring-the-ios-sdk-7th-edition-wallace-wang/

Postman for API Testing: A Beginner's Guide: Learn to


test APIs like a pro with Postman with Real-World
Examples and Step-by-Step Guidance Parvin

https://ebookmass.com/product/postman-for-api-testing-a-
beginners-guide-learn-to-test-apis-like-a-pro-with-postman-with-
real-world-examples-and-step-by-step-guidance-parvin/

Building Real-Time Marvels with Laravel: Create Dynamic


and Interactive Web Applications 1st Edition Sivaraj
Selvaraj

https://ebookmass.com/product/building-real-time-marvels-with-
laravel-create-dynamic-and-interactive-web-applications-1st-
edition-sivaraj-selvaraj/

Building Real-Time Marvels with Laravel: Create Dynamic


and Interactive Web Applications Sivaraj Selvaraj

https://ebookmass.com/product/building-real-time-marvels-with-
laravel-create-dynamic-and-interactive-web-applications-sivaraj-
selvaraj/

Learn Enough Ruby to Be Dangerous Michael Hartl

https://ebookmass.com/product/learn-enough-ruby-to-be-dangerous-
michael-hartl/
Build Mobile Apps
with SwiftUI and
Firebase
Learn SwiftUI and Firebase by Building
Real-World Applications Communicating
with a Backend

Sullivan De Carli
Build Mobile Apps
with SwiftUI and
Firebase
Learn SwiftUI and Firebase by
Building Real-World
Applications Communicating
with a Backend

Sullivan De Carli
Build Mobile Apps with SwiftUI and Firebase: Learn SwiftUI and Firebase
by Building Real-World Applications Communicating with a Backend
Sullivan De Carli
Charleville-Mézières, France

ISBN-13 (pbk): 978-1-4842-9283-9 ISBN-13 (electronic): 978-1-4842-9452-9


https://doi.org/10.1007/978-1-4842-9452-9

Copyright © 2023 by Sullivan De Carli


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, 233
Spring Street, 6th Floor, New York, NY 10013. 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 booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
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/Build-Mobile-­Apps-
with-SwiftUI-and-Firebase. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
I’d like to thank Tiago, Luis, and all the people who helped
me learn how to code along the way. I’d also like to thank
my girlfriend and my family for their support.
Table of Contents
About the Author���������������������������������������������������������������������������������ix

About the Technical Reviewer�������������������������������������������������������������xi

Chapter 1: Introduction to SwiftUI��������������������������������������������������������1


Xcode Walk-Through���������������������������������������������������������������������������������������������1
What Makes SwiftUI Different�������������������������������������������������������������������������������8
Coding with SwiftUI���������������������������������������������������������������������������������������������11
Summary������������������������������������������������������������������������������������������������������������15

Chapter 2: Introduction to Firebase����������������������������������������������������17


What Is Firebase?�����������������������������������������������������������������������������������������������17
Setting Up a Firebase Account and Project���������������������������������������������������������20
Firebase Walk-Through���������������������������������������������������������������������������������24
Connect Your iOS Application to Firebase�����������������������������������������������������������27
You Might Be Wondering What This File Is For����������������������������������������������34
Summary������������������������������������������������������������������������������������������������������������41

Chapter 3: Playing with Firestore�������������������������������������������������������43


Introducing the MVVM Design Pattern����������������������������������������������������������������44
Create Data to Firestore��������������������������������������������������������������������������������������46
Read Data from Firestore������������������������������������������������������������������������������������55
Pass Data from Views�����������������������������������������������������������������������������������������58

v
Table of Contents

Update Data from Firestore���������������������������������������������������������������������������������62


Delete Data from Firestore����������������������������������������������������������������������������������65
Summary������������������������������������������������������������������������������������������������������������68

Chapter 4: Authenticate Users with Firebase Auth�����������������������������71


Setting Up Firebase Authenticate������������������������������������������������������������������������72
Manage User Sessions����������������������������������������������������������������������������������������75
Sign Up with Email and Password����������������������������������������������������������������������79
What If You Forget Your Password?���������������������������������������������������������������85
Secure the Firestore Database����������������������������������������������������������������������������88
Security Rules�����������������������������������������������������������������������������������������������92
Summary������������������������������������������������������������������������������������������������������������94

Chapter 5: Advanced Firestore�����������������������������������������������������������95


Introducing Our New Project�������������������������������������������������������������������������������95
Why Are We Creating a New Firebase Project?���������������������������������������������97
Call the Backend with Async/Await�������������������������������������������������������������������100
Summary����������������������������������������������������������������������������������������������������������104

Chapter 6: Manage Pictures with Firebase Storage�������������������������105


Access the iPhone Camera and Library������������������������������������������������������������105
Upload Pictures to Firebase Storage�����������������������������������������������������������������108
Integrate Large Documents with Firestore�������������������������������������������������������112
Summary����������������������������������������������������������������������������������������������������������116

Chapter 7: Authenticate with Apple��������������������������������������������������117


Set Up the Project and “Sign in with Apple”�����������������������������������������������������118
Integrate “Sign in with Apple”��������������������������������������������������������������������������120
Summary����������������������������������������������������������������������������������������������������������128

vi
Table of Contents

Chapter 8: Adding Features Without Coding�������������������������������������129


Exploring Firebase Extension����������������������������������������������������������������������������129
Track Our App Usage with Analytics�����������������������������������������������������������������132
Securing Our Database�������������������������������������������������������������������������������������134
Summary����������������������������������������������������������������������������������������������������������135

Index�������������������������������������������������������������������������������������������������137

vii
About the Author
Sullivan De Carli is currently Consultant for Deloitte, where he works as
an iOS developer with several Fortune 500 companies as clients. He began
his development journey in 2017 and graduated from the Apple Developer
Academy in Naples, Italy, in 2020. He has built apps for personal projects
and successful entrepreneurial ventures.

ix
About the Technical Reviewer
Alexander Nnakwue is a self-taught software engineer with experience
in backend and full-stack engineering. With an experience spanning
more than four years, he loves to solve problems at scale. Currently, he
is interested in startups, open source web development, and distributed
systems. In his spare time, he loves watching soccer and listening to all
genres of music.

xi
CHAPTER 1

Introduction to
SwiftUI
This first chapter is meant for beginners in iOS development. I will walk
you through the main functionalities of Xcode, your tool to create projects
and run code. Then, we will create a simple application: a map displaying
a few places.
This way, we will explore some SwiftUI APIs to build the user interface
and some basics of Swift such as creating a model. Let’s get started!

Xcode Walk-Through
To build an iOS application, you first need Xcode. This software made by
Apple will be your program to write Swift code, create a user interface,
build and debug your project, and much more. Think of it like Photoshop
for photography or Sketch and Figma for UI design.
The software is available on the Mac App Store; you can easily
download it from there. Navigate to the App Store on your Mac and search
for Xcode, and then click DOWNLOAD (I have “OPEN” since I already
downloaded it):

© Sullivan De Carli 2023 1


S. De Carli, Build Mobile Apps with SwiftUI and Firebase,
https://doi.org/10.1007/978-1-4842-9452-9_1
Chapter 1 Introduction to SwiftUI

Figure 1-1. Download Xcode from the App Store

At the time of writing, the latest version is Xcode 14.1. I recommend


you download at least Xcode 14; otherwise, a lot of functionalities will not
be replicable throughout the book.
The download will take some time since it is quite a heavy program
(7GB). Once you have downloaded it, you can open it. It will ask you if you
want to download additional components for macOS and watchOS. You
can skip this step since we only need iOS for the scope of this book.
Then, this page will appear, inviting you to start a project:

2
Chapter 1 Introduction to SwiftUI

Figure 1-2. Xcode welcome screen

Click Create a new Xcode project, and the following page will appear:

3
Chapter 1 Introduction to SwiftUI

Figure 1-3. Xcode – choosing a template

Xcode will suggest to you a series of templates. In fact, you can build a
lot of things using the Swift language such as an Apple Watch app, a game
that runs on the iPhone, a Safari extension, or a utility app for Mac. We will
select App from the iOS platform for now. It will be the same for the other
projects although our application will also be able to run on the iPad.
Now, I invite you to enter the word Discover; this is going to be the
name of our first project written with SwiftUI.
Also, make sure that the SwiftUI framework is selected together with
the Swift language.
(Make sure to have your name or enterprise in the Team field. If
you’re new to Xcode, it is your Apple account that you use for the App
Store. That should be your team’s name. For me it is “Sullivan De Carli
(Personal Team).”

4
Chapter 1 Introduction to SwiftUI

Figure 1-4. Xcode – settings for the project

Great! Now save your project wherever you prefer; I usually save it to
my desktop. We can start exploring the Xcode functionalities!

5
Chapter 1 Introduction to SwiftUI

Figure 1-5. Xcode – walk-through


Xcode is composed of different tabs; each one has a different purpose:
1 – The left tab is showing all the files that your project contains. By
default, there will be three main folders: One contains your app entry
point named “DiscoverApp” like an index.html for the web developers.
The ContentView comes by default; it is a starter template to present a user
interface. Finally, there is an Assets folder that you can use to store your
images and videos; this is useful since it will reduce the size of any assets
that you upload. This folder will also contain your app logo.
The other two are for testing purposes. From there you can run tests to
see if your code is robust or the user interface is responding accordingly.
There is also a filter at the bottom to search through and a series of tabs at
the top that will be useful when we are running the application.
2 – The second is where we are going to work! From there we can
write code and see the content of our files. Also, in SwiftUI, every SwiftUI
view comes with a struct called Preview (inside the green square). This is
responsible to present you the screen on the right. If you delete this code,
you won’t be able to use the Canva feature.

6
Chapter 1 Introduction to SwiftUI

3 – Canva has been introduced in 2019; it is an easy way to see the user
interface that you are building live. From there, you can see how your app
looks when you make changes in the code.
For example, try to add the keyword .bold() in the second panel right
after the Text("Hello, world!"). Your text will turn to bold right away.
4 – The right tab is going to be your points of information for the file
you are currently viewing. From there, you can rename it, change the
programming language, and even edit some user interface elements, such
as fonts and spacing between elements if you navigate to the last button
at the top. Note that we won’t be using this section much throughout
the book.
Now, you can build your project. I invite you to click the build button,
at the top left of Xcode as follows:

Figure 1-6. Simulator running on Xcode

7
Chapter 1 Introduction to SwiftUI

Once you click it, a Simulator app will pop up and present you with a
virtual iPhone running your application. You can also select other types of
iPhones or iPads at the top panel so you can see how what you are building
reacts to different screen sizes.
There are a lot of things to cover about Xcode. So far, what I highlighted
are the main things to know and recognize, but we will discover more
functionalities by coding. We will do just that in the next chapter and build
our first application using Xcode and SwiftUI.

What Makes SwiftUI Different


SwiftUI has been introduced in 2019 by Apple at their WWDC; it is the
declarative framework used by developers around the world to build
applications for the Apple platforms. At the time of writing, we are at
version 4.
SwiftUI makes you write better apps with less code as Apple states. Is
it true? Prior to SwiftUI, we were using UIKit, an imperative framework
introduced by Apple in 2014 to build user interfaces. It is still available, but
it is slowly being replaced by Apple, since the company shifted the focus to
SwiftUI.
To understand the evolution of these two frameworks, let’s do a
comparison by building two user interfaces composed of a list that
displays elements from 1 to 10. For one of them, we will use UIKit, and the
other will be built using SwiftUI. The user interface will look like this:

8
Chapter 1 Introduction to SwiftUI

Figure 1-7. A list displaying on an iPhone

Observe the following code in UIKit:

import UIKit

class ViewController: UIViewController, UITableViewDelegate,


UITableViewDataSource {

    let tableView = UITableView()

    override func viewDidLoad() {


        super.viewDidLoad()
        view.addSubview(tableView)
        tableView.register(UITableViewCell.self,
forCellReuseIdentifier: "Cell")
        tableView.dataSource = self
        tableView.delegate = self
    }

     override func viewDidLayoutSubviews() {


         super.viewDidLayoutSubviews()
         tableView.frame = view.bounds
    }

9
Chapter 1 Introduction to SwiftUI

    func tableView(_ tableView: UITableView,


numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    func tableView(_ tableView: UITableView, cellForRowAt


indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:
"Cell", for: indexPath)
        cell.textLabel?.text = "\(indexPath.row)"
        return cell
    }

As you can see, we import the framework UIKit at the top. We pass two
delegates to our class: UITableViewDelegate and UITableViewDataSource.
Then, we declare a UITableView to create the list that we manually added
in the viewDidLoad method.
This method is being called when the view is being loaded, presented
to the user. We also conform to this protocol with our two functions that
return the numbers of rows and what they are composed of, here a cell
with a text displaying the number of the current row.
Quite a bit of code to conform to the protocol and to present a basic
user interface composed of ten rows.
Let’s now code it using SwiftUI:

import SwiftUI

struct ContentView: View {


    var body: some View {
        List(0..<10) { index in

10
Chapter 1 Introduction to SwiftUI

            Text("\(index)")
        }
    }
}

That’s it! As you can see, with SwiftUI our list is way shorter. We
import the framework at the top of the file. Then we directly declare a list
in the body variable that contains 11 elements from zero to ten and its
composition: a text displaying one to ten. It is literally two lines of code to
create a List, much clearer and easier to read.
Now that we see that SwiftUI is much more efficient to build user
interfaces, we are going to introduce a few bases. We will create a little
application to introduce some APIs.

C
 oding with SwiftUI
To understand SwiftUI, the best thing to do is to build an application. So
we are going to build a simple application that displays a few places on a
map. Along with it, I will explain a few basics about SwiftUI.
Head to the Xcode project we created earlier called Discover. Run the
application. You should have the following starter template:

11
Chapter 1 Introduction to SwiftUI

Figure 1-8. Xcode running with Simulator

To recreate this screen, since it features Apple Maps, we need to import


a framework called MapKit to access their APIs. So add the following line
of code at the top of the file:

import MapKit

Then, right over the code struct ContentView, copy/paste the


following code:

struct Place: Identifiable {


    var id = UUID()
    var title: String
    var coordinate: CLLocationCoordinate2D
    var architecte: String
}

We just implemented a model to create a few items from this model.


Let me explain to you the code:

12
Chapter 1 Introduction to SwiftUI

struct in Swift is used to store variables. Here we give the name of this
struct: Place.
Identifiable is a protocol used to make this class identifiable. Since
we are going to display the data in a List, we need to make each item
identifiable.
Then, we give a few variables of type UUID to give a unique identifier,
String for words, and CLLocationCoordinate2D to pass coordinates
(latitude and longitude).
Great, we just created what is called a model, a modularization of our
object (Place) with a few variables.
Now we can take care of our user interface.
Right under struct ContentView, add the following line of code:

@State private var region = MKCoordinateRegion(center: CLLocat


ionCoordinate2D(latitude: 41.9028, longitude: 12.4964), span:
MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))

What is the @State variable?

A property wrapper type that can read and write a value


managed by SwiftUI.
—From the Apple documentation

This will allow us to manipulate data. Here we are passing coordinates


that correspond to the coordinates of the city of Rome.
Then, we are declaring a constant, which contains an array of places.
An array declared by [] is useful to present a series of data.

13
Chapter 1 Introduction to SwiftUI

Copy/paste the following code right after the @State you declared earlier:

let annotations = [
        Place(title: "Fontana di Trevi", coordinate: CLLoc
ationCoordinate2D(latitude: 41.900833, longitude:
12.483056), architecte: "Nicola Salvi"),
        Place(title: "Pantheon", coordinate: CLLocationCoo
rdinate2D(latitude: 41.8986, longitude: 12.4768),
architecte: "Marcus Agrippa"),
        Place(title: "Villa Medici", coordinate: CLLocation
Coordinate2D(latitude: 41.908, longitude: 12.483),
architecte: "Bartolomeo Ammannati"),
        Place(title: "Colosseo",  coordinate: CLLocationCoor
dinate2D(latitude: 41.890278, longitude: 12.492222),
architecte: "Flavian Emperors")
    ]

Great, now we have all the necessary input to present locations on a


Map and a few places to display.
Inside the body variable, replace the VStack with the following line
of code:

Map(coordinateRegion: $region, annotationItems: annotations) {


               MapMarker(coordinate: $0.coordinate)
           }

This Map modifier will present a map in our application. We are


passing a region parameter that we defined earlier with the coordinates of
Rome, using the $ sign; it is the syntax to use with the @State variable. Also,
we are adding annotations (the four places that we declared earlier).
To present these annotations, we are using MapMarker with the
coordinates passed in our object.
If you correctly follow these short tutorials, you should have your
Canva presenting a map with four annotations as follows:

14
Chapter 1 Introduction to SwiftUI

Figure 1-9. Our map application

Summary
If you are new to Swift, this chapter has been useful to introduce you to
Xcode, your tool to build applications for the Apple platform. Then, we saw
the basics of Swift by creating a model and writing static data. Then, we
used a map to display annotations, importing from the framework MapKit
to access Apple’s map APIs.
Now that we have a clearer idea of how to create a static model of data
and present them, we can go ahead and talk about the backend. The next
chapters will be focused on Firebase and how to download data from a
backend, present them, modify them, and handle user input. Let’s dive
into the Firebase console.

15
CHAPTER 2

Introduction
to Firebase
I am going to introduce you to the Firebase console and how to create a
new project and connect an iOS application.
We will cover what is Firebase, why we are selecting this backend over
others, and the advantages and disadvantages that come with it.
There is a walk-through to create your first Firebase project directly
from the web browser. We are also going to connect our iOS application to
talk to Firebase through its APIs.
By the end of this chapter, you will be able to create a new iOS app
linked to the Firebase backend. For reference, please go to the Firebase
documentation at the following link: HTTPS://FIREBASE.GOOGLE.COM/
DOCS/IOS/SETUP.

What Is Firebase?
Firebase is what we call a backend as a service (BaaS), which means that
rather than running your server to run your online applications, you pass
through their services to read, write, update, and delete data, authenticate
your users, and many more things!
Have a look at the following graphic that shows a native iOS
application built with a custom backend running on the cloud:

© Sullivan De Carli 2023 17


S. De Carli, Build Mobile Apps with SwiftUI and Firebase,
https://doi.org/10.1007/978-1-4842-9452-9_2
Chapter 2 Introduction to Firebase

Figure 2-1. An iOS app built with a backend host on a cloud service

As you can see, the app will be communicating with a virtual machine
usually coded in Ruby, Node.js, or PHP, itself hosted by a cloud service
(which could also be physical, but it is rare nowadays) such as Amazon
Web Services, Google Cloud Platform, Microsoft Azure, or whatever
service. In complex applications with a large user base, it usually requires
a frontend developer, in our case an iOS developer; a backend developer
to develop the logic and the APIs; and finally a DevOps, responsible
for bringing all of that to a cloud service and distributing it. A full-stack
developer can also do it, but it is rare and requires a lot of experience.
Now, let’s have a look at an iOS application built with Firebase:

Figure 2-2. An iOS app built with Firebase’s backend

18
Chapter 2 Introduction to Firebase

As you see, the architecture is way easier. Our iOS is notifying and
receiving data from Firebase using their APIs that come along with great
documentation. There is no need to write code on the server side or host
it to a third-party provider since it is already built on top of Google Cloud
with no deployment needed by you! Additionally, you can still run backend
code, thanks to the Firebase Cloud function, if you want to achieve more
complex interactions later. In terms of a team, you need an iOS developer,
and you’re ready to publish an application on the App Store.
We have seen how much easier it is to use Firebase rather than running
your backend code, but there is more: it comes with a series of out-of-the-­
box tools that help speed up your development.
For example, they have their APIs to authenticate a user with multiple
third-party providers such as Apple, Facebook, Google, etc. They have
Google Analytics preinstalled and ready to go.
Additionally, there are a series of extensions with third-party providers
to sign up users to an email list, adding in-app purchase with RevenueCat
with no code required.
You can discover them at this link:

HTTPS://FIREBASE.GOOGLE.COM/PRODUCTS/EXTENSIONS

Firebase comes with advantages and disadvantages. Here is the list:


The pros:

–– You are faster to ship your application. You don’t need to write
code on the backend unless you need to execute some more
advanced functionalities.

–– You have access to Google Cloud Platform with no operations


needed on your side.

19
Chapter 2 Introduction to Firebase

–– You get out-of-the-box authenticate APIs with third parties. You


don’t need to use an API for Google sign-in and another one for
Facebook sign-in, for example. You can pass directly through
Firebase’s APIs.

–– You don’t have to worry about scalability and managing servers.


The cons:

–– The data don’t belong to you to store them. The best thing to do
is to run a snapshot of your data every day and store it in a
secure place.

–– You could be limited in some advanced applications where you


need full control of the backend because the user interface is
relying heavily on the backend.

Overall, Firebase is a great option if you want to release an application


as fast as possible, the cheapest since you don’t need to hire a backend
developer. You can concentrate on what matters: building your product
and monitoring the usage so you can implement features that your users
want, which is also easier thanks to event follow-up and app analytics
powered by Google Analytics that comes “for free.”
That being said, let’s discover Firebase, create our first project, and
make our iOS app communicate with it.

Setting Up a Firebase Account and Project


To start on Firebase, you need to sign up for their services, which belong
to Google, so you will need a Gmail account. If you don’t already have
one, sign up for a Gmail account first. Then go to the Firebase website
(https://firebase.google.com ), click “Get started,” and you will be on
your Firebase’s console. You should see something like this:

20
Chapter 2 Introduction to Firebase

Figure 2-3. Homepage of the Firebase console

Click Create a project to create your first project on Firebase. I am


going to guide you through every step, so you don’t get lost on your way. It
requires you to follow three straightforward steps.

21
Chapter 2 Introduction to Firebase

Let’s start with the first one:

Figure 2-4. Firebase new project, step 1 – project name

For step 1, you just need to give it a name. I invite you to name it “Note”
since it is the application we are going to build in the next chapter, but it
doesn’t matter.
The second step is to enable Google Analytics:

22
Chapter 2 Introduction to Firebase

Figure 2-5. Firebase new project, step 2 – Google Analytics

This comes for free with Firebase, and it gives you access to basic
data about how long your users are spending time on each screen, user
usage over weeks, etc. You can even add events later to create funnels.
For example, you will be able to find out how many users complete the
signup process and then, for all those registered users, how many of them
complete a purchase. For now, simply enable it and click Continue.

23
Chapter 2 Introduction to Firebase

The third step looks like this screen:

Figure 2-6. Firebase new project, step 3 –Configure Google


Analytics account

For now, we can simply use the Firebase default account. If you have
a website with Google Analytics tags to track usage and you want to build
a related iOS application, you might want to select directly your Google
Analytics account during this step. Click Create project, and you have
created your first project on Firebase.

Firebase Walk-Through
You’re now on the Firebase console. This is going to be the backbone of
your application. Let me introduce it to you although we’re going to dive in
with our development in the next chapters.

24
Chapter 2 Introduction to Firebase

Once the project is created, you will arrive at something like this:

Figure 2-7. The Firebase console

This is a classic dashboard. In the left panel, you will get access to
different menus categorized into four sections:

Build – This is the place that we are going to explore


the most. Here we will set up our authentication
with third-party providers, create our database, and
write our security rules and add extensions, a no-­
code solution.

Release & Monitor – Once we have released our


application on the App Store or even on TestFlight,
you will be able to see reports if our users
experienced crashes and even implement backend-­
powered distribution, which is not part of this
book but good to have a look at because it is really
powerful for iteration.

25
Chapter 2 Introduction to Firebase

Analytics – From here you will have access to data


usages of our app for free and implement some
funnel from our code to monitor how a journey is
being completed by our users.

Engage – This is especially powerful for stores and


games. It offers features to send notifications with
promotions, present advertisements with AdMob,
and run A/B testing.

As you can imagine, there are a lot of features to cover with Firebase.
For the scope of this book, you will be 90% of the time between Xcode and
Firebase’s Build section.
On the right, you have your Google account that you can switch as
with every Google product and a “Go to docs” button. It is always good to
refer to the documentation when you want to implement something or
understand better how it works.
At the top, there is your project name. From there you can switch
between projects.
The “Spark plan” label is your billing plan; this one is for free
and comes with quite a lot of things. There is also the “pay as you go”
connected to Google Cloud Platform. You will be billed based on your
users’ usages and the number of documents written and read.
For this book, the Spark plan will be enough although we might need
to switch to pay as you go when we implement some extensions later
because they run on Google Cloud Platform. It is going to be a few cents
anyway since we are at a development stage.
It is now time to add our iOS application to talk to Firebase!

26
Chapter 2 Introduction to Firebase

Connect Your iOS Application to Firebase


It’s time to link our application to Firebase. To achieve this we will need to
do some back-and-forth between Xcode and the Firebase console.
This walk-through is based on the Firebase documentation (https://
firebase.google.com/docs/ios/setup). At the time of writing, the
documentation doesn’t include SwiftUI, so I recommend you follow it
through.
First, we need to create a new Xcode project. Go ahead and click Create
a new Xcode project:

Figure 2-8. Xcode – welcome screen

Then, in terms of templates, it is going to be a classic application, so


select the App template under the iOS platform:

27
Chapter 2 Introduction to Firebase

Figure 2-9. Xcode – selecting an App template

Finally, we need to give a name to our project. We will call it Note since
this is the application we are building in the next chapter. Make sure to
select SwiftUI for Interface. The use of Core Data is not required since we
will have Firebase to store data:

28
Chapter 2 Introduction to Firebase

Figure 2-10. Xcode – options for a new project

You can save your project wherever you prefer. I saved it on my


desktop. Now that our project is created, let’s see how to connect it to
Firebase. You can navigate back to the Firebase console. From the project
overview, click iOS+ as follows:

29
Chapter 2 Introduction to Firebase

Figure 2-11. Firebase console – adding an iOS app

Firebase will present you a page inviting you to complete a five-step


process, to connect your app to Firebase.
The first thing you need to do is to grab the Apple bundle ID. You
will find it in Xcode on your main target. It is usually composed like the
following:
com.[name of your team].[name of your project].

Please, check the following screenshot if you don’t know where it is


located:

30
Chapter 2 Introduction to Firebase

Figure 2-12. Xcode – where to find the bundle identifier

Once you have copied your identifier, you can copy/paste it. You also
have the option to leave a nickname and the App Store ID, but these are
optional:

31
Chapter 2 Introduction to Firebase

Figure 2-13. Add Firebase to your Apple app – step 1

Click Continue, and this will bring you to step 2, downloading the
GoogleService-Info.plist file. Click the blue download button and save
your file wherever you prefer. I saved it on my desktop:

32
Chapter 2 Introduction to Firebase

Figure 2-14. Add Firebase to your Apple app – step 2

Now that you have your file, you can drag and drop it to your Xcode
folder from where you saved it. In my case, I dragged the file with my
mouse directly to Xcode and then clicked the Finish button.
Make sure that Create folder references, Copy items if needed, and the
target Note are selected

33
Chapter 2 Introduction to Firebase

Figure 2-15. Drag and drop the GoogleService-Info.plist file to Xcode

Now that you have the file added to your project, Firebase will be able
to recognize your app when you are making the APIs call it. You can now
click Next.

You Might Be Wondering What This File Is For


The GoogleService-Info.plist is a file that contains all the information to
communicate between your application and the Firebase backend; it
contains the API key, the URL where your data will be collected, and a
series of information to set up your project.
Make sure to add properly the file; otherwise, Firebase will not be able
to find the essential information to connect to your iOS application and
cause a crash when you call it.

34
Chapter 2 Introduction to Firebase

In case you lose this file for some reason, you can always find it and
download it from the Firebase console. Next to the project overview,
there is a settings button. Click Project settings and then scroll down to
SDK setup and configuration, and you will be able to download it again
from there:

Figure 2-16. Finding the GoogleService-Info.plist file in the console

That being done, we can go to step 3 and install the Firebase Software
Development Kit (SDK). This can be achieved in multiple ways. The most
popular are CocoaPods and Swift Package Manager. We will use the latter
in our case.
You can copy the URL suggested by Firebase indicated in the following
figure (https://github.com/firebase/firebase-ios-sdk):

35
Chapter 2 Introduction to Firebase

Figure 2-17. Add Firebase to your apple app – step 3

Once you have copied it, go back to Xcode and, at the top-left level,
click File ➤ Add Packages…, and a pop-up screen will appear. Enter the
URL you just copied into the search bar, and the Firebase-ios-sdk package
should appear as in the following figure:

36
Chapter 2 Introduction to Firebase

Figure 2-18. Xcode – adding the package

Note Since I already added it to previous projects, it is already


appearing under the section “Recently used.”

Click the blue button at the bottom right called Add Package, and
fetching will start and will propose you to add a product. For now, we will
only use the three following packages:
–– FirebaseFirestore

–– FirebaseFirestoreSwift

–– FirebaseAuth

Only these three modules will be necessary for our next chapters:
replicating the Apple Notes app. However, for the following project, we will
also be using Firebase Analytics, Firebase Storage, and more.

37
Another random document with
no related content on Scribd:
There is at least one white Negro in Africa. The man in the centre, who said both
his parents were as black as the women beside him, is pure Sudanese, yet he has
a fair skin, rosy cheeks, and flaxen hair.
Services at the Coptic Church at Khartum sometimes last five hours, while the
worshippers stand barefooted on the cold floors. The Copts, direct descendants of
the ancient Egyptians, have been Christians since St. Mark preached at
Alexandria.

“Do you see many changes in the condition of the natives since
the British occupation?”
“Yes. They are doing far better than in the past. They wear more
clothing, they have more wants, and are working to supply them.
Formerly many went naked, and as there was no security of property
and few wants, they had no incentives to save. When we came here
the taxes were levied at the will of the rulers, so the rich native was
sure to be persecuted. Now since the taxes are fairly levied, the
people are learning that their savings will be respected. They are
coming to have faith in us. Our first business was to make them
realize that we intended to treat them fairly and honestly, and I
believe we have succeeded. We had also to organize the country, so
that it might be able to pay the expenses of its government. We are
fast reaching that stage.”
“Is your native population increasing?”
“Very rapidly,” replied Sir Reginald. “I am surprised at the large
number of children that have been born since we took possession of
the Sudan. The provinces fairly swarm with little ones. During a
recent trip through Kordofan I carried a lot of small coin with me to
give to the children. The news of this travelled ahead, so as soon as
we approached a village we would be met by the babies in force.
Nearly every peasant woman came forward with a half dozen or
more little naked blacks and browns hanging about her, and the
children ran out of the tents as we passed on the way. The
Sudanese are naturally fond of children, especially so when times
are good and conditions settled as they are now. They want as many
children and grandchildren as the Lord will give them, and as most of
the men have two or three wives, it is not an uncommon thing for a
father to have several additions to his family per year.”
“Your Excellency has been travelling on camel back through
Kordofan. Is that country likely to be valuable in the future?”
“I do not see why it should not be,” replied the Governor-General.
“It is one of the stock-raising regions of this part of the world,
producing a great number of cattle and camels. Much of the meat
now used in Khartum comes from Kordofan, and camels are bred
there for use throughout the Libyan and Nubian deserts. The
southern half of the country, which is devoted to cattle, is inhabited
by stock-raising people. Every tribe has its herds, and many tribes
are nomadic, driving their stock from pasture to pasture. North of
latitude thirteen, where the camel country begins, one finds camels
by the thousands. That section seems to be especially adapted to
them.”
“What is the nature of the land west of Kordofan?”
“I suppose you mean Darfur. That country is a hilly land traversed
by a mountain range furnishing numerous streams. It is well
populated, and was for a long time a centre of the slave trade. The
natives there are comparatively quiet at present, although every now
and then a war breaks out between some of the tribes. This is true,
too, in Kordofan. The people are brave and proud, and they have
frequent vendettas.”

[1] Since this interview with Sir Reginald occurred he has


retired from office at the end of a lifetime spent in the Sudan. He
will always be considered one of the best authorities on that vast
and comparatively unknown region, and his views, especially
when expressed, as here, in the height of his activities, are of
perennial value.
CHAPTER XXII
WHY GENERAL GORDON HAD NO FEAR

One of my talks with Sir Francis Reginald Wingate was of a more


personal nature dealing with some of the events in which he was an
historic figure. I had asked His Excellency if he would not some day
write a new book on the Sudan. He wrote “Mahdism and the
Egyptian Sudan” some years ago; and a few years later published a
work entitled “Ten Years’ Captivity in the Mahdi’s Camp.” He also
translated and edited Slatin Pasha’s “Fire and Sword in the Sudan”
and for years his life has been a part of the history of the country and
his experiences such that no man living can tell about it better than
he. The Sirdar replied:
“I may write another book some day. I have kept notes of things
which I have observed and which have occurred from time to time,
and putting them together may give me occupation when I retire. At
present my chief interest is in the development of the country, and I
am too much occupied with that and with my duties here to find any
time for literary work.”
Afterward our conversation turned to the conditions which
prevailed here while the Mahdi was waging war against the English.
Sir Reginald, then General Wingate, was one of the officers in
command of the British troops and is full of vivid stories of those
terrible times. As we talked we were standing on the portico jutting
out from the second story of the government palace. We were
looking down the Nile and in plain view of the little island of Tuti over
the way. General Wingate went on to tell a story of General Gordon’s
bravery and absolute lack of fear:
“It was on this site that Gordon had his headquarters during a
siege of the Mahdi. He lived in a rough building with windows
opening toward that island, upon which the enemy had an
encampment. It was his custom of an evening to sit in his room
facing the river and write in his diary. The Mahdists saw his light and
shot at it again and again but, notwithstanding this, General Gordon
did not change his place for writing. His friends remonstrated and the
citizens of Khartum sent in a petition to him either to write in the back
of the house or to hide his light behind a screen. This petition was
brought in by a delegation from the town, which had assembled in
front of the headquarters awaiting an answer. As they stood there,
lights were put in every front window and they saw General Gordon
go from window to window making himself, as they thought, a fair
mark for the Dervishes on the island. At last he came out and
standing in the full blaze of the light said:
“‘Gentlemen, there is an old story that when the Lord made
mankind He did so with two great piles of material before Him. One
of the piles was composed of the clay of which man is made and the
other of the fear that often makes one less than a man. As the Lord
worked, He took up a handful of clay, shaped it into a human form,
and then sprinkled it over with a handful from the pile of fear. And so
He went on making man after man until at last He took up the stuff of
which He made me. There was plenty of clay for my body but when
He looked about for fear with which to sprinkle it, He found that the
pile of fear had all been used up, so the result is I do not know what
fear is.’”
In the dry Upper Nile valley piled-up grain awaits unprotected the boats which
will distribute it along the river. The provinces of Darfur and Kordofan alone can
produce enough dura to feed the entire Sudan.

No matter how far up the Nile or how deep in the desert they live, “backsheesh”
is the cry of the children of Egypt and the Sudan. Young and old alike have learned
the trick of asking a fee for posing.
British experiments in cotton culture in the Sudan have been most successful
and the quality of the product compares favourably with Egyptian varieties.
Irrigation projects under construction will shortly add 100,000 acres to the cotton-
growing area.

The chief public building in Khartum is the Sirdar’s palace, built by Kitchener on
the site of Gordon’s murder. Over it float British and Egyptian flags and two
sentries guard its door, one British, one Sudanese.

General Gordon’s bravery was far beyond that of other world


heroes. He fought here until the last. When the Arabs finally
overcame his troops and entered his palace, he sternly demanded of
them where their master was. They replied by plunging their spears
into his body. As he fell, they dragged him down the steps and cut off
his head to be sent to the Mahdi. His body was left to the mercy of
the fanatics, who rushed forward by thousands to dip their swords
and spears in his blood. They fairly cut it to pieces, and the blood,
which had stained the steps and walls of the palace, remained there
until the Khalifa decided to make that place a dwelling for his harem
and had it washed away.
The British have done all they could to carry out Gordon’s mission
in the Sudan; that is, to break up slavery. This region was once one
of the chief slave markets of the continent. The poor wretches were
brought by the thousands from Central Africa to Khartum and
Omdurman, and taken thence down to Egypt. Before the British rule
there were military stations in different parts of the country, which
became centres of the trade, and the White Nile was a famous slave
route. Later on the Arabs raided the natives of Central Africa and
sent up their captives to Khartum. The trade was somewhat checked
while Gordon ruled, but it broke out again under the Mahdi. When
the British took hold, Omdurman was one of the chief markets,
slaves being brought in in droves from all parts of the country. Since
then the buying and selling of the blacks has been stopped, as far as
possible, but it is still carried on in some of the provinces, and it will
be a long time before it can be absolutely eradicated. Sixty-seven
slave dealers were captured and tried not so long ago. Fifty-eight
were convicted, more than fifty receiving sentences of from one to
seven years each.
While I was at Asyut, Dr. Alexander, president of the Training
College there, told me how a poor Swiss boy broke up the slave
trade of Upper Egypt. Said he: “This incident occurred just before the
British occupation. The boy, whose name was Roth, got the idea that
it was his mission to aid in abolishing slavery, and that his field lay in
the Sudan. He had no money, but he worked his way to Alexandria
and thence up the Nile to Asyut, landing here without a cent. He
applied for work at the mission schools, telling us his plans, and we
finally arranged for him to teach French. While doing so he studied
Arabic and went out through the country to learn all he could about
slavery. He spent his vacations living with the people, travelling
about and visiting the villages. It was then contrary to law to sell
slaves in Egypt, but Roth learned that the trade was going on, and
that caravans were bringing them from the Sudan into Upper Egypt.
They were sent from here to Tunis and Tripoli and thence to
Constantinople. One day he came into the mission and said that a
big slave caravan was encamped outside Asyut, and that the men
hid their prisoners in caves during the day and sold them at night. He
begged me to go with him to the governor and demand that they be
punished. I did go, but was not able to do anything.
“After this,” continued Dr. Alexander, “Roth despaired somewhat,
but said he intended to go to Cairo to get the English consul-general
to help him. He did so and convinced the consul-general that his
story was true. The two demanded of Riaz Pasha, then foreign
minister, that the sale of slaves be stopped. Since Roth had the
English Government behind him, the Egyptian government had to
respect him. Giving him a company of two hundred soldiers, they
told him to go back to Asyut and capture the caravan. It was
probably their intention to notify the slave dealers in time, so they
could get away. But Roth defeated this move. He stopped his special
train outside the town, divided his company into two bands,
surrounded the caravan and took the traders and the sixty-seven
slaves they had with them. He brought the poor creatures here to the
mission school saying he wanted me to hold them as the Egyptians
would not dare to take them from under the American flag.
“Shortly after this there came a message from the governor of the
province ordering that the slaves be given up. The messengers were
backed by soldiers, but nevertheless I refused, declaring it was
impossible on account of the absence of Dr. Hogg, the
superintendent of the mission. The next day, when Dr. Hogg arrived,
the governor sent for him and abused him for not giving up the
slaves. Thereupon Dr. Hogg charged him with wanting to evade the
law, and told him that if Asyut had any respect for the law or had a
governor who was anything of a man, the caravan would have been
arrested sooner and the owners punished. He demanded that this be
done, and as a result the slave dealers and slaves were taken to
Cairo to be tried there. The government of Egypt, not daring to
whitewash the transaction, was forced to dismiss the governor and
punish the slave dealers. Roth was afterward appointed an agent of
the Egyptian government to keep down the slave trade. He came to
the Sudan and carried on his work there in connection with Gordon
and Slatin Pasha. Slatin speaks of him in his book entitled Fire and
Sword in the Sudan. He died while fighting the trade there.”
CHAPTER XXIII
OMDURMAN, STRONGHOLD OF THE MAHDI

One of the queerest cities I have ever visited is Omdurman, once


the capital of the Mahdi and to-day the great native commercial
centre of the Sudan. Omdurman stretches for more than six miles
along the Nile at the point where the Blue Nile flows in from the
distant Abyssinian hills. Opposite the city is Tuti Island, while beyond
the island on the farther bank of the White Nile is Khartum. Founded
by the Mahdi, or the Mohammedan Messiah, and the scene of the
most atrocious cruelties and extravagances of the Khalifa who
succeeded him, Omdurman once contained about one million of
African Sudanese. It was then a great military camp, composed of
one hundred thousand mud houses and inhabited by tribes from all
parts of the million square miles embraced in the realm of that
savage ruler. The Khalifa forced the people to come here to live that
he might have their services in time of war, allowing them to go
home only to cultivate and harvest their crops, which they were
obliged to bring back for sale. He made Omdurman his seat of
government, and he had his own residence here inside a great wall
of sun-dried brick which enclosed about sixty acres, and in which
was an open-air mosque of ten acres or more. Here he had his
palace and here he kept his four hundred wives. Just outside the city
he fought the great battle which ended in his downfall and the
destruction of his capital.
According to Mohammedan tradition, the Prophet said that there
would arise among the Faithful a sort of Messiah, or Mahdi, which
means in Arabic “he who is guided aright.” Mohammed Ahmed, later
known as the Mahdi, claimed to be such a leader, and so he founded
the empire which lasted until the Battle of Omdurman. He got the
people to believe he had been appointed Mahdi by God, and that he
had been taken by the Prophet himself into the presence of the
apostles and saints, and by them commanded to cleanse and purify
the Mohammedan religion.
He did anything, however, but practise what he preached. By the
Koran, smoking and drinking are strictly prohibited, and
extravagance is frowned upon, but in the height of his power the
Mahdi and his chiefs lived lives of the most horrible drunkenness,
extravagance, and vice. Mohammed Ahmed is described by Slatin
Pasha, who was for years a prisoner of the Mahdists in Omdurman,
as a tall, broad-shouldered, powerfully built man, with a black beard
and the usual three scars on each cheek. He had the V-shaped gap
between his two front teeth which the Sudanese consider a sign of
good luck and which is said to have been the cause of his popularity
among women. Their name for him was Abu Falja, “the man with the
separated teeth.” His beautifully washed woollen garments were
always scented with a mixture of musk, sandalwood, and attar of
roses. This perfume, which was known as the “odour of the Mahdi,”
was supposed to equal, if not surpass, that of the dwellers of
Paradise.
After the siege and capture of Khartum the people who had held
out against the Mahdists were put to the most unspeakable tortures,
all of them, that is, except the young women and girls. These were
reserved for the Mahdi’s harem. For weeks after the battle there
went on in his camp at Omdurman the business of choosing from the
fairest for his own establishment, while the ones he rejected were
turned over to his chief favourites and advisers. After Mohammed
Ahmed’s death, which occurred close on the heels of his victory, the
Khalifa had the Mahdi’s widows and all the women of his harem
imprisoned in a high-walled compound guarded by eunuchs. None
was allowed to marry or go out into the world again.
The Omdurman of the present, which is laid on practically the
same lines as that of the past, covers almost the same ground,
although it has much fewer people. During my trip of to-day I climbed
to the top of the old palace of the Khalifa, and took a look over the
city.
The houses stretch along the Nile for seven or eight miles, and the
water front is fringed with a thicket of boats. Some of the town is on
the main stream, and reaches out from the river in all directions. It is
a city of mud in every sense of the word. Of its many thousand
houses there are not a score which are of more than one story, and
you can count on your fingers the houses made of burnt brick. When
I first rode through it I asked my guide if the holes in the walls had
been made by cannon-balls at the time of the fighting. “Why, man,”
he replied, “those are the windows.” Most of the houses are flat
roofed, with drain pipes extending out over the street so that when it
rains the water pours down on the necks of the passers-by. The one-
story mud houses have mud walls about them, and the mud stores
face streets paved only with mud. The walls of the vast inclosure of
the Khalifa are made of mud bricks, while the houses inside, which
now form the quarters of the Anglo-Egyptian soldiers and officers,
are of sun-baked dirt.
The Khalifa was so afraid of being assassinated that he had all the
houses near his palace torn down, shut himself up in his walled
inclosure, and kept at his side a great bodyguard, to which he was
forever adding more soldiers. His special apartments in the palace
were considered the last word in luxury. They had beautiful curtains
and carpets of silk and actually boasted big brass beds with
mosquito nets, spoils from the European houses at Khartum.
Standing on the Khalifa’s palace, one can follow many of the
streets with one’s eye. Some of them are of great width, but the
majority are narrow and winding. The whole city, in fact, is a labyrinth
cut up by new avenues laid out by the British, with the holy buildings
and the Khalifa’s old government structures in the middle. But the
British are improving conditions in Omdurman, and have elaborate
plans for its development, including a fine park in the centre of the
city.
Each of the towns of the Sudan has a British official to rule it; but
under each such governor is a sub-governor who must be a native
Egyptian. This man is called the mamour and is the real executive as
far as carrying out the orders of the government is concerned. He
represents the natives, and understands all about them and their
ways. The mamour at Omdurman is an ex-cavalry officer of the army
of the Khedive who fought with the British in their wars against the
Khalifa. He speaks English well, and as he understands both Turkish
and Arabic, he was able to tell me all about the city as we went
through.
Being followers of the Prophet, the Bisharin consider a difference of fifty years in
ages no bar to matrimony. This girl wife probably spent a whole day in
straightening out her kinky hair with a mixture of grease and clay, and adorning it
with beads.

Omdurman, which once had a population of a million, is a strange city of mud.


The houses and stores are one-story flat-roofed buildings with drain pipes
extending out over the street that drip on the passers-by when it rains.
Within sight of the British and their civilization, the Sudanese blacks live
miserably, crowded into their burrow-like mud huts, possessing only a few pots
and bowls and the sheets of calico in which many of the women wrap themselves.

I came down the Blue Nile from Khartum in a skiff. The distance is
about five miles, but we had to tack back and forth all the way, so
that the trip took over two hours. The mamour met me on landing.
He had a good donkey for me, and we spent the whole day in going
through the city, making notes, and taking the photographs which
now lie before me.
The people are stranger than any I have ever seen so far in my
African travels. They come from all parts of the Sudan and represent
forty or fifty-odd tribes. Some of the faces are black, some are dark
brown, and others are a rich cream colour. One of the queerest men
I met during my journey was an African with a complexion as rosy as
that of a tow-headed American baby and hair quite as white. He was
a water carrier, dressed in a red cap and long gown. He had two
great cans on the ends of a pole which rested on his shoulder, and
was trotting through the streets carrying water from one of the wells
to his Sudanese customers. His feet and hands, which were bare,
were as white as my own. Stopping him, I made him lift his red fez to
see whether his hair was white from age. It was flaxen, however,
rather than silver, and he told me that his years numbered only
twenty-five. The mamour, talking with him in Arabic, learned that he
was a pure Sudanese, coming from one of the provinces near the
watershed of the Congo. He said that his parents were jet-black but
that many men of his colour lived in the region from whence he
came. I stood him up against the mud wall in the street with two
Sudanese women, each blacker than the ink with which this paper is
printed, and made their photographs. The man did not like this at
first, but when at the close I gave him a coin worth about twenty-five
cents he salaamed to the ground and went away happy.
I am surprised to see how many of these Sudanese have scars on
their faces and bodies. Nearly every other man I meet has the marks
of great gashes on his cheeks, forehead, or breast, and some of the
women are scarred so as to give the idea that terrible brutalities
have been perpetrated upon them. As a rule, however, these scars
have been self-inflicted. They are to show the tribe and family to
which their owners belong. The mamour tells me that every tribe has
its own special cut, and that he can tell just where a man comes from
by such marks. The scars are of all shapes. Sometimes a cheek will
have three parallel gashes, at another time you will notice that the
cuts are crossed, while at others they look like a Chinese puzzle.
The dress of the people is strange. Those of the better classes
wear long gowns, being clad not unlike the Egyptians. Many of the
poor are almost naked, and the boys and girls often go about with
only a belt of strings around the waist. The strings, which are like
tassels, fall to the middle of the thigh. Very small children wear
nothing whatever.
A number of the women wear no clothing above the waist, yet they
do not seem to feel that they are immodest. I saw one near the ferry
as I landed this morning. She was a good-looking girl about
eighteen, as black as oiled ebony, as straight as an arrow, and as
plump as a partridge. She was standing outside a mud hut shaking a
sieve containing sesame seed. She held the sieve with both hands
high up over her head so that the wind might blow away the chaff as
the seed fell to the ground. She was naked to the waist, and her
pose was almost exactly that of the famed “Vestal Virgin” in the
Corcoran Art Gallery at Washington.
Omdurman is the business centre of the Sudan. Goods are sent
from here to all parts of the country, and grain, gum arabic, ostrich
feathers, ivory, and native cotton are brought in for sale. The town
has one hundred restaurants, twenty coffee houses, and three
hundred wells. It has markets of various kinds, and there are long
streets of bazaars or stores in which each trade has its own section,
many of the articles sold being made on the spot. One of the most
interesting places is the woman’s market. This consists of a vast
number of mat tents or shelters under each of which a woman sits
with her wares piled about her. She may have vegetables, grain, or
fowls, or articles of native cloth and other things made by the people.
The women have the monopoly of the sales here. Men may come
and buy, but they cannot peddle anything within the women’s
precincts nor can they open stands there. I understand that the
women are shrewd traders. Their markets cover several acres and
were thronged with black and brown natives as the mamour and I
went through.
Not far from the market I came into the great ten-acre square upon
which centre the streets of the stores. There are a number of
restaurants facing it. In one corner there is a cattle market where
donkeys, camels, and horses are sold. The sales are under the
government, to the extent that an animal must be sold there if a good
title is to go with it. If the transfer is made elsewhere the terms of the
bargain may be questioned, so the traders come to the square to do
their buying and selling.
It is strange to have shops that sell money. I do not mean stock
exchanges or banks, but real stores with money on the counters,
stacked up in bundles, or laid away in piles on the shelves. That is
what they have in Omdurman. There are caravans going out from
here to all parts of north central Africa, and before one starts away it
must have the right currency for the journey. In financial matters
these people are not far from the Dark Ages. Many of the tribes do
not know what coinage means; they use neither copper, silver, nor
gold, and one of our dollars would be worth nothing to them. Among
many of the people brass wire and beads are the only currency.
Strange to say, every locality has its own style of beads, and its
favourite wire. If blue beads are popular you can buy nothing with
red ones, while if the people want beads of metal it is useless to offer
them glass.
In some sections cloth is used as money; in others salt is the
medium of exchange. The salt is moulded or cut out of the rocks in
sticks, and so many sticks will buy a cow or a camel. The owner of
one of the largest money stores of the Sudan is a Syrian, whose
shop is not far from the great market. He told me that he would be
glad to outfit me if I went into the wilds. I priced some of his beads.
Those made of amber were especially costly. He had one string of
amber lumps, five in number. Each bead was the size of a black
walnut, and he asked for the string the equivalent of about fifteen
American dollars. The string will be worn around some woman’s
bare waist, and may form the whole wardrobe of the maiden who
gets it.
Not far from this bead money establishment the mamour and I
entered the street of the silversmiths. This contains many shops in
which black men and boys are busy making the barbaric ornaments
of the Sudan. Jewellery is the savings bank of this region, and many
of the articles are of pure silver and pure gold. Some are very heavy.
I priced rings of silver worth five dollars apiece and handled a pair of
gold earrings which the jeweller said were worth sixty dollars. The
earrings were each as big around as a coffee cup, and about as
thick as a lead pencil at the place where they are fastened into the
ear. The man who had them for sale was barefooted, and wore a
long white gown and a cap of white cotton. His whole dress could not
have cost more than ten dollars. He was a black, and he had half-a-
dozen black boys and men working away in his shop. Each smith sat
on the ground before a little anvil about eight inches high and six
inches wide, and pounded at the silver or gold object he was making.
In another shop I saw them making silver anklets as thick as my
thumb, while in another they were turning out silver filigree work as
fine as any from Genoa or Bangkok. The mamour asked two of the

You might also like