Beginning
SwiftUI
Greg Lim
Copyright 2021 Greg Lim
All rights reserved.
Copyright 2021 by Greg Lim
All rights reserved.
No part of this book may be reproduced in any form or by any electronic or mechanical means including information storage and retrieval systems, without permission in writing from the author. The only exception is by a reviewer, who may quote short excerpts in a review.
First Edition: March 2021
Table of Contents
Preface
About this book
In this book, we take you on a fun, hands-on and pragmatic journey to learning iOS 14 development using SwiftUI. You'll start building your first SwiftUI app within minutes. Every section is written in a bite-sized manner and straight to the point as I dont want to waste your time (and most certainly mine) on the content you don't need. In the end, you will have the skills to create an app and submit it to the app store.
In the course of this book, we will cover:
- Chapter 1: Introduction
- Chapter 2: Body Mass Index Calculator
- Chapter 3: To Do List App Using List
- Chapter 4: Persistent Data Using Core Data
- Chapter 5: Extending Core Data to CloudKit
- Chapter 6: Getting Data from an API: GitHub Users
- Chapter 7: Machine Learning with Core ML
- Chapter 8: C.R.U.D. Notes App with Firebase/Firestore
- Chapter 9: Building Cross Platform Apps in SwiftUI
The goal of this book is to teach you SwiftUI development in a manageable way without overwhelming you. We focus only on the essentials and cover the material in a hands-on practice manner for you to code along.
Requirements
No previous knowledge of iOS development required, but you should have basic programming knowledge.
Getting Book Updates
To receive updated versions of the book, subscribe to our mailing list by sending a mail to . I try to update my books to use the latest version of software, libraries and will update the codes/content in this book. So do subscribe to my list to receive updated copies!
Contact and Code Examples
Visit www.greglim.net/swiftui to obtain the source codes used in this book. Comments or questions concerning this book can also be directed to the same.
Chapter 1: Introduction
Welcome to Beginning SwiftUI iOS 14 Development! I'm Greg and I'm so excited that you decided to come along for this. With this book, you will go from absolute beginner to having your app submitted to the App Store and along the way, equip yourself with valuable iOS app development skills.
SwiftUI makes it easier to build user interfaces across all Apple platforms with Swift. It uses a declarative syntax where you simply state what your user interface should do.
Before SwiftUI, developers used UIKit and Storyboard to design user interfaces. We drag and drop UI controls on to View Controllers and connect them to outlets and actions on the View Controller classes. We then update view controls and handle events that occur through delegates. If you would like to learn iOS development using UIKit and Storyboard, check out my best-selling book or contact me at support@i-ducate.com .
SwiftUI in contrast is a state-driven, declarative framework. There is no more dragging and dropping in the storyboard. Layouts are specified declaratively using code. For example, you can state that you want a list of items consisting of text views and then describe the value for each view.
struct ContentView: View {
var body: some View {
List{
Text("Write SwiftUI book")
Text("Read Bible")
Text("Bring kids out to play")
Text("Fetch wife")
Text("Call mum")
}
}
}
Your code is easier to read and write than before, saving you time and maintenance.
Working Through This Book
This book is purposely broken down into brief chapters where the development process of each chapter will center it on different essential topics to develop apps for the iPhone. The book takes a practical hands-on approach to learning through practice. You learn best when you code along with the examples in the book. Along the way, if you encounter any problems, drop me a mail at where I will try to answer your query.
Get a Mac
Before we proceed on, you will need to have a Mac running on at least macOS version of 10.15.4 (Catalina) to run Xcode 12. This is because to use Live Preview and design canvas features in Xcode, you need at least macOS Catalina (10.15).
If you do not yet have a Mac, the cheapest option is to get a Mac Mini and if you have a higher budget, get a higher model or iMac with more processing power. You might have heard of the option to run Mac on Windows machines for iOS development, but I do not recommend it. Unexpected problems will arise in development and publishing to the App store that can be avoided by just using a Mac. If you are serious about developing iOS apps and publishing them on the App Store, getting a Mac is a worthwhile investment.
Downloading Xcode
Next, there is an essential piece of software you need to have on your computer before we can move forward. It's called Xcode and is an integrated development environment (IDE) provided by Apple to write Swift code and make iOS apps. It includes the code editor, graphical user interface editor, debugging tools, an iPhone/iPad simulator (to test our apps without real devices) and much more. Le t s get it downloaded before proceeding.
Download the latest version of Xcode 12 (at time of writing) from the Mac App Store (fig. 1).
Figure 1
You will need an Apple ID to login and download apps from the Mac App store. If you do not already have one, sign up for an account (https://appleid.apple.com/account). You will also need an Apple ID to be able to deploy your app to a real iPhone/iPad device for testing.
The installation of Xcode might require you to update your version of MacOS. At this boo k s time of writing, the MacOS required is Catalina version 10.15.4.
Installing Xcode
Just like any other Mac App, Mac App store will take care of the downloading and installation of Xcode for you. Do note that installation of Xcode 12 requires 20-30 GB of space available for the installation to proceed and installation takes quite some time. Once the installation is complete, you should see the Xcode icon on your computer.
Swift and Xcode
I'm going to be introducing you to two terms that you're going to encounter throughout this book. One of those is Swift and the other one is Xcode. Swift is the programming language we use to make iPhone apps. Swift came out in 2014. Previous to that, the programming language used to make iPhone apps was Objective C. But Objective C was complicated. Many developers new to the space of iOS development found that it was hard to read and write. Swift then was introduced. Swift is specifically designed with beginners in mind and even experienced programmers think of Swift as a really clean and beautiful language.
Xcode is the program that allows us to make iPhone apps. We're going to type Swift into Xcode and also use Xcode for designing the visual side of our app like where we want a button, what color do we want it to be, where do we want to place our table view, etc.
Throughout this book, these are the two skills that we will be improving upon step by step.
This book is written for a beginner in iOS development. So, you do n t need to have any prior iOS development experience. But if you have some iOS development experience, you're going to feel pretty familiar with what's going on.