Book Image

SwiftUI Projects

By : Craig Clayton
Book Image

SwiftUI Projects

By: Craig Clayton

Overview of this book

Released by Apple during WWDC 2019, SwiftUI provides an innovative and exceptionally simple way to build user interfaces for all Apple platforms with the power of Swift. This practical guide involves six real-world projects built from scratch, with two projects each for iPhone, iPad, and watchOS, built using Swift programming and Xcode. Starting with the basics of SwiftUI, you’ll gradually delve into building these projects. You’ll learn the fundamental concepts of SwiftUI by working with views, layouts, and dynamic types. This SwiftUI book will also help you get hands-on with declarative programming for building apps that can run on multiple platforms. Throughout the book, you’ll work on a chart app (watchOS), NBA draft app (watchOS), financial app (iPhone), Tesla form app (iPhone), sports news app (iPad), and shoe point-of-sale system (iPad), which will enable you to understand the core elements of a SwiftUI project. By the end of the book, you’ll have built fully functional projects for multiple platforms and gained the knowledge required to become a professional SwiftUI developer.
Table of Contents (13 chapters)

API design

In this section, we are going to set up our API class. Once we have the respective file, we will use it minimally. I always try to use a simple API design and I feel this is really to the point. Even though we'll be using Combine here a lot more than we have the rest of this book, this won't be excessive and it will be fairly easy for you to understand what's going on. Here, we will create an API class and add some code to our View model that our views will communicate with. Let's jump in and create our API class.

Creating the API class

Here, we need to create an API for every page in this app, which will include the dashboard, roster, schedule, and game details dashboard. First, create a new folder called Networking and then create a new file named API. Inside the Networking folder, update the import statements to the following:

import Combine
import SwiftUI

Next, add the following struct:

struct API {
	// Add next step here

We want...