Categories
Uncategorized

Chapter 1: Introduction

Dear Reader ♥️

First, thank you for purchasing this book! This means a lot to us and helps us to continue the work we are doing.

In this book, we teach you everything you need to know about SwiftUI to develop your own beautiful iOS applications. And this as quickly and easily as never before!

We start by explaining the fundamentals of how SwiftUI works and immediately get our hands dirty with building our first SwiftUI apps.

We will teach you everything step-by-step and as simple and concise as possible. To make everything understandable and comprehensible we tried to include as much code, illustrations etc. as possible.

For every app we build in this book, we link the whole source code at the end of each chapter, so check it out if you get stuck. Of course, you can always write us a message if anything is unclear!

What is SwiftUI 🤷‍♂️ 

SwiftUI was announced by Apple at the WWDC19 event and is described as “an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift”. In fact, SwiftUI makes it amazingly easy to build your apps exactly the way you want them to look.

Until recently, the most common way to build iOS apps was to use storyboards. Simplified, you created the UI (short for “user interface”) of your app by dragging and dropping, arranging and constraining elements and by connecting them to your code. But to see the result you had to compile and run your app every time you made changes to it.

This not only took up unnecessary time each time but could also easily interrupt your workflow.

As already mentioned, when working with storyboards, you always had to deal with two “layers”: The storyboard UI on one side and the written code on the other side. Since these layers can easily differ, this approach often led to unforeseen bugs and crashes.

Building apps with old-school storyboards often leads to a lack of visual feedback, bugs and frustration.

With SwiftUI, Apple introduced a new framework that works completely differently. Instead of having two separate layers to work with, the UI and the written code, SwiftUI combines and merges them. This becomes more comprehensible when we look at how the SwiftUI framework approach works.

With SwiftUI, you use code to describe how your app should look. With this new syntax approach, you just describe how your interface should look like and how it should behave.

SwiftUI follows a declarative syntax approach which means that we describe in code how our interface should look.

Look at the image above. You see that every piece of the UI – the toggle, the text field, the stepper, the text field group, the slider with its text and images and the button – is described by code.

And that is one of the great advantages of using SwiftUI! Everything you write in code is immediately reflected in your live preview. No more time-intense run & compile workflow anymore. Everything you describe in your code is also displayed directly and you already know what your app will look like while you are still coding.

That’s not all! You can even manipulate the UI inside the Live preview itself. For example, you can drop and drag another text object or manipulate the color of a certain object, as you’ll see later on. Every change in the live preview also affects your code and vice versa. Take a look at the following example where we change the font type and color of the text by editing it visually.

This new workflow saves us a lot of time and makes building apps much more intuitive. Because code and UI are always linked and dependent on each other, you don’t have to worry about broken outlets and actions anymore.

Technical requirements for running SwiftUI 🏃‍♂️

SwiftUI works with Xcode version 11 and upwards, which you can download for free from the Mac App Store. But we strongly recommend using Xcode 13 to have access to all the latest SwiftUI features. Note that Xcode 13 is only compatible with running at least macOS Big Sur.

Personal requirements 🤓

Although we try to explain everything as simple as possible and always step-by-step, we recommend that you are at least familiar with the basics of the Swift programming language. However, you don’t have to be a professional programmer to understand and apply what you will learn in this book. If you are a beginner, we recommend that you read our free Swift Programming for Beginners eBook. After learning the concepts described in this book, you should be ready to go!

By the way, you don’t necessarily need to be familiar with building iOS apps using UIKit, although it could give you a slight advantage when we talk about interfacing with UIKit and SwiftUI. But don’t worry when you don’t know what we’re talking about right now. Everything will be explained soon enough!

Now, let’s get our hands dirty and start building some awesome SwiftUI apps!