1.
Introduction
“SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift.”
— Apple
SwiftUI is a new paradigm in Apple-related development. In 2014, after years of programming apps with Objective-C, Apple surprised the world with a new open-source language: Swift. Since its release, Swift has updated and evolved. And it is becoming one of the most beloved and powerful programming languages today.
SwiftUI’s introduction in 2019 created another opportunity for a paradigm shift in the industry. After years of using UIKit and AppKit to create user interfaces, SwiftUI presented a fresh, new way to create UI for your apps. In many ways, SwiftUI is much simpler and powerful than its predecessors, and even more, it is cross-platform over the Apple ecosystem.
One of the most important things, though, is SwiftUI’s declarative nature. For years, developers have worked with imperative programming models, dealing with state-management problems and complex code. But now, you have in your hands a declarative, straightforward way to build amazing user interfaces. And don’t worry; if you loved working with UIKit or AppKit, rest assured that you can integrate those frameworks with your SwiftUI code.
SwiftUI has been continuously improving throughout these years. Swift has become one of the industry standards for progressive, modern programming languages. Now that we are in the 5th edition of this book, we can confirm that SwiftUI is following the same path.
Come embark upon the exciting voyage waiting for you inside this book. You’ll learn all the tips and tricks we have to share in this new way of creating user interfaces. You´ll discover what SwiftUI has to offer, how powerful it is, and how quickly and easy it is to start working with it.
Book Structure
The book is divided into six sections and twenty-two chapters in which you will learn how to build great and engaging declarative user interfaces for your apps.
-
Section I: Diving Into SwiftUI: The first four chapters will introduce SwiftUI. You will work with a SwiftUI adapted version of our famous color-matching tutorials game: BullsEye. You will start by learning the terminology, how to preview your user interface in the canvas and how to use the power of reusable modifiers. In this first section, you will even get started with testing and debugging to create powerful tested apps.
-
Section II: Building Blocks of SwiftUI: User interfaces require controls for users to interact with them. Learn all you need to know about most of the available user controls and input interfaces such as TextFields, Buttons, Toggles, Sliders, and many more. Get to know the capabilities of vertical and horizontal stacks, container views and dive deeper into modifiers and how to implement them. To do so, you will work this time with Kuchi an impressive language flashcard app.
-
Section III: State & Data Flow: Your app will probably not stick to a single view. You must learn how to bind data to the UI, how reactive updates work and how to manage state changes. You will keep improving the Kuchi app by adding more advanced controls like calendar or color pickers. You´ll learn how to trigger updates to the user interface, how to test it and how to implement gestures. And to make it even better, you´ll learn how to navigate your app with VoiceOver and how you can improve it with accessibility for people with certain disabilities.
-
Section IV: Navigation & Data Display: To learn about navigation and how to provide data to your users, you will build a flight-information app. Set a navigation hierarchy to navigate through the different views. Create tabs and learn how to display information in grids or lists. And become an expert on all of them. Alert your users and pop up messages with Sheet and Alert Views. Many more advanced concepts are waiting for you in these chapters!
-
Section V: UI Extensions: The airport app needs a more visual approach to display all its information. So learn about graphics, gradients, and how to display information with drawings and custom graphics. Make it more appealing by using animations and adding transitions. And finally, get out of your comfort zone with complex interfaces and learn more advanced concepts. After this, you will be able to build almost any interface you can imagine.
-
Section VI: SwiftUI for macOS: As you might know, SwiftUI is cross-platform, so you can use it to develop apps for different Apple devices. Prepare a document-based markdown app for macOS and check by yourself how easily you can transfer all the knowledge you’ve been acquiring throughout the book to building macOS apps with SwiftUI. And even better, learn how you can start with an existing iOS app and how you can reuse the code, views, and assets and how easily you can adapt it for the mac.
About This Book
We wrote this book with beginner-to-advanced developers in mind. The only requirements for reading this book are a basic understanding of Swift and iOS development. SwiftUI is a recent and new paradigm, so developers of all backgrounds are welcome to discover this great technology with us. As you work through this book, you’ll progress from beginner topics to more advanced concepts in a paced, familiar fashion.
A great starting point before this book is our SwiftUI Apprentice book https://www.kodeco.com/books/swiftui-apprentice. But if you’ve worked through our classic beginner books — the Swift Apprentice https://www.kodeco.com/books/swift-apprentice and the UIKit Apprentice https://www.kodeco.com/books/uikit-apprentice — or have similar development experience, you’re also ready to read this book. You’ll additionally benefit from a working knowledge of design patterns — such as working through Design Patterns by Tutorials https://www.kodeco.com/books/design-patterns-by-tutorials — but this isn’t strictly required.