Swift
Apprentice
Seventh Edition
By the raywenderlich Tutorial Team
Ehab Amer, Alexis Gallagher, Matt Galloway, Eli Ganim,
Ben Morrow & Cosmin Pupz
Swift Apprentice
Ehab Amer, Alexis Gallagher, Matt Galloway, Eli Ganim, Ben Morrow & Cosmin Pupz
Copyright 2021 Razeware LLC.
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an as is basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of their own respective owners.
Book license
By purchasing Swift Apprentice, you have the following license:
You are allowed to use and/or modify the source code in Swift Apprentice in as many apps as you want, with no attribution required.
You are allowed to use and/or modify all art, images and designs that are included in Swift Apprentice in as many apps as you want, but must include this attribution line somewhere inside your app: Artwork/images/designs: from Swift Apprentice, available at www.raywenderlich.com.
The source code included in Swift Apprentice is for your personal use only. You are NOT allowed to distribute or sell the source code in Swift Apprentice without prior authorization.
This book is for your personal use only. You are NOT allowed to sell this book without prior authorization, or distribute it to friends, coworkers or students; they would need to purchase their own copies.
All materials provided with this book are provided on an as is basis, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
All trademarks and registered trademarks appearing in this guide are the properties of their respective owners.
Before You Begin
This section tells you a few things you need to know before you get started, such as what youll need for hardware and software, where to find the project files for this book and more.
What You Need
To follow along with the tutorials in this book, youll need the following:
A Mac running macOS Big Sur 11.6 or later. with the latest point release and security patches installed. This is so you can install the latest version of the required development tool: Xcode.
Xcode 13 or later. Xcode is the main development tool for writing code in Swift. You need Xcode 13 at a minimum, since that version includes Swift 5.5 Xcode playgrounds. You can download the latest version of Xcode for free from the Mac App Store, here: apple.co/1FLn51R
If you havent installed the latest version of Xcode, be sure to do that before continuing with the book. The code covered in this book depends on Swift 5.5 and Xcode 13 you may get lost if you try to work with an older version or work outside the playground environment that this book assumes.
Book Source Code & Forums
Book source code
The materials for this book are all available in the GitHub repository here:
You can download the entire set of materials for the book from that page.
Forum
Weve also set up an official forum for the book at https://forums.raywenderlich.com/c/books/swift-apprentice. This is a great place to ask questions about the book or to submit any errors you may find.
Dedications
Thanks to my family for their unconditional support, and my beautiful Merche for being a wonderful blessing.
Ehab Amer
To my wife and kids Ringae, Odysseus, and Kallisto.
Alexis Gallagher
To my amazing family who keep putting up with me spending my spare hours writing books like this.
Matt Galloway
To my loved ones: Moriah, Lia and Ari.
Eli Ganim
For MawMaw. A talented cook, a loving smooch, a worthy opponent in chicken foot; a home weaver. Her blessing abides beyond her time.
Ben Morrow
To my awesome girlfriend Oana, my sweet dogs Sclip and Nori and my lovely cats Grisi and Porto for believing in me all the way.
Cosmin Pupz
About the Authors
Ehab Amer is an author of this book. He is a very enthusiastic Lead iOS developer with a very diverse experience, from building games to enterprise applications and POCs, especially when exploring new technologies. In his spare time, TV shows take the majority, followed by video games. When away from the screen, he goes with his friends for escape room experiences or to explore the underwater world through diving.
Alexis Gallagher is an author of this book. Hes worked in consulting, science, iOS development, startup management, and theater. Perhaps the only software engineer in San Francisco who was born there, he lives there now with his family, and works at Google on machine learning research and applications.
Matt Galloway is an author of this book. He is a software engineer with a passion for excellence. He stumbled into iOS programming when it first was a thing, and he has never looked back. When not coding, he likes to brew his own beer.
Eli Ganim is an author of this book. He is a Software Engineer whos passionate about teaching, writing and sharing knowledge with others. He lives in Israel with his wife and kids.
Ben Morrow is an author of this book. He delights in discovering the unspoken nature of the world. Hell tell you the surprising bits while on a walk. He produces beauty by drawing out the raw wisdom that exists within each of us.
Next page