Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
SwiftUI Projects
SwiftUI Projects

SwiftUI Projects: Build six real-world, cross-platform mobile applications using Swift, Xcode 12, and SwiftUI

Arrow left icon
Profile Icon Craig Clayton
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (11 Ratings)
Paperback Dec 2020 410 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Craig Clayton
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (11 Ratings)
Paperback Dec 2020 410 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

SwiftUI Projects

Chapter 2: SwiftUI Watch Tour

We've looked at things SwiftUI can do; now, we will examine how they look on each device. In this chapter and the next, we will work exclusively with watchOS and SwiftUI. Even if you are not doing watchOS development, everything can be applied to the iPhone, iPad, and macOS. There are some subtle differences, but overall everything is the same.

Since there is no specific design for this chapter, we'll look at the default behaviors that we get out of the box. WatchOS has many default looks that are harder to customize than on the other devices. We'll use this chapter to focus on execution, and in the next chapter, we'll work with a specific design. Let's get started working with SwiftUI.

In this chapter, we'll cover the following:

  • Creating a SwiftUI PageView in watchOS
  • Creating a Bar Chart, Wedge Chart, and Activity Ring
  • Creating a list in watchOS

This chapter has a starter file called SwiftUIWatchTour...

Technical requirements

Getting started

We are going to build a small app that will just get your feet wet. We will create a List which we will use to navigate us through our small app. Charts will link to charts and Colors will link to another colors list. One will show you Charts, and the other will show you a List from an Array. You will create three charts in this chapter – Bar, Activity Ring, and Wedge. We will build out a PageView, which will allow us to swipe from left to right to see each one. For the List, you will create a list and display it using an array. Here are what the screens will look like when we are finished:

Figure 2.1

Building out our navigation

SwiftUI is now fully supported in watchOS 7, which means we do not have to work with some of the older controllers pre watchOS 6. We will first create our entire navigation, and then we will go back and build out each view. Let's get started by opening ContentView first.

Creating a static list

Our List, in this view, is going to be a static list with just two links. One will present a modal, and the other will do the standard push to detail view. Add the following after the struct declaration:

@State private var isPresented = false

In the last chapter, we skipped @State because it was not in scope, and I will do it again as I cover this in greater detail in Сhapter 5, Car Order Form – Data. But I will, for now, just say we are creating a Boolean that keeps track of the modal presentation. Next, inside the body variable, replace Text ('Content View') with the following:

List {
    Button(&apos...

Creating a chart Page-View navigation

Next, we are going to create a Page View navigation controller. Just as you would expect on a phone, you will be able to swipe from the right to left and see different content on each page. You will also see some dots at the bottom of the page, which shows which page is being displayed currently.

Open ChartsView and let's get started. Inside the body variable, replace Text('Charts View') with the following:

TabView { // Step 1
    BarChartView() // Step 2
    WedgeChartView() 
    RingView() 
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))     // Step 3

We just added all of the code for ChartsView, so let's look at what we did:

  1. We wrap all of our views inside a TabView.
  2. Next, we set up each page by just listing them inside the TabView.
  3. We set the .tabViewStyle() modifier to PageTabViewStyle(indexDisplayMode...

Creating a SwiftUI watch list

We are going to display a SwiftUI List view. Our List is going to display a list of colors. First, we need to create a color model.

Open the ColorModel file inside the Model folder and add the following:

struct ColorModel: Identifiable {
    var id = UUID()
   	var name: String
}

This struct has two properties: id and name. We have also set our model so that it conforms to Identifiable. When using a List in SwiftUI, our List is required to be unique, and there are two ways to handle this. We can either pass data, for example, the name as our unique ID, or we can use UUID and use this as our ID. The more you work with SwiftUI, the more ways you will encounter to handle Identifiable. If your data was coming from a feed, then you could use id if it were unique.

Open ColorsView.swift and add the following code inside the ColorsView struct, before the body:

@State var colors: [ColorModel] = [ ColorModel(name...

Using Swift previews

We covered this in the last chapter, but before we write any SwiftUI code, we will look at a SwiftUI file. Open BarChartView and you'll see our struct view, which we looked at in the previous chapter. If you scroll to the bottom, you will see static var previews. Previews are used to preview our design without having to launch the simulator. You should see a blank space to the right of your code, and at the top of this, you will see a button named Resume:

Figure 2.5

Figure 2.5

Click Resume, and you will see the preview appear:

Figure 2.6

Figure 2.6

Let's move on to building some charts.

Charts

Building charts is pretty fun in SwiftUI because it requires very little code. Here is an example of the three screens that we are looking to create in this section:

Figure 2.7

Figure 2.7

We will start on the Bar Chart first using the Capsule shape.

Bar charts

Bar charts are a great way to display information to users. In this example, we will create a static Bar Chart that you can use to display data on the watch. We can also take all of these examples and show them on the larger screens of other devices. Whenever we work in SwiftUI, we will use Swift Previews to review our work, making our workflow go much faster than having to wait for the simulator to launch and display. Please note that to use Swift Previews, you must be on macOS Catalina. If you are not, then just run the simulator.

Creating a header

First, we will start by creating our header for our view. This view is just two text views stacked horizontally next to each other. Open BarChartView...

Summary

In this chapter, we got to work on some basic SwiftUI views. This chapter was a primer to help you get a bit more comfortable using SwiftUI. From here on out, our UIs will become more complex. In the next chapter, we will build an NBA Draft app for the Apple Watch. We will work with animations as well as loading data from a plist. I hope you're excited as I am because this is the kind of stuff that made me want to write this book.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn SwiftUI with the help of practical cross-platform development projects
  • Understand the design considerations for building apps for different devices such as Apple Watch, iPhone, and iPad using SwiftUI’s latest features
  • Work with advanced SwiftUI layout features, including SF Symbols, SwiftUI grids, and forms in SwiftUI

Description

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.

Who is this book for?

SwiftUI Projects is intended for anyone who is already comfortable with Swift. We do not cover Swift topics in detail, so you need to be familiar with these already. All of the SwiftUI topics are taught as if this is the first time you've learned them and will gradually get more difficult.

What you will learn

  • Understand the basics of SwiftUI by building an app with watchOS
  • Work with UI elements such as text, lists, and buttons
  • Create a video player in UIKit and import it into SwiftUI
  • Discover how to leverage an API and parse JSON in your app using Combine
  • Structure your app to use Combine and state-driven features
  • Create flexible layouts on iPad

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 11, 2020
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781839214660
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 11, 2020
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781839214660
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 132.97
SwiftUI Projects
$38.99
Mastering Swift 5.3
$38.99
SwiftUI Cookbook
$54.99
Total $ 132.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Chapter 1: SwiftUI Basics Chevron down icon Chevron up icon
Chapter 2: SwiftUI Watch Tour Chevron down icon Chevron up icon
Chapter 3: NBA Draft – Watch App Chevron down icon Chevron up icon
Chapter 4: Car Order Form – Design Chevron down icon Chevron up icon
Chapter 5: Car Order Form – Data Chevron down icon Chevron up icon
Chapter 6: Financial App – Design Chevron down icon Chevron up icon
Chapter 7: Financial App – Core Data Chevron down icon Chevron up icon
Chapter 8: Shoe Point of Sale System – Design Chevron down icon Chevron up icon
Chapter 9: Shoe Point of Sale System – CloudKit Chevron down icon Chevron up icon
Chapter 10: Sports News App – Design Chevron down icon Chevron up icon
Chapter 11: Sports News App – Data Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(11 Ratings)
5 star 36.4%
4 star 9.1%
3 star 9.1%
2 star 9.1%
1 star 36.4%
Filter icon Filter
Top Reviews

Filter reviews by




Nicholas Jan 23, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Okay so this is the second book on SwiftUI that I've read through from packt. I have enjoyed their materials so far and Ill go into detail below if you'd like to read why.This is a book with follow along projects, BUT they open with a quick review of the basics (which I needed) and it helps get your feet wet before you dive into a full project.The watch project was a great follow along as I have never built anything for the apple watch before so that was really fun.The second build was a little dry for me but I have to admit it showcased some great features, such as blurring backgrounds when you click certain buttons, and overall good UI/UX info that Ill likely use in my own future app.The financial app was really neat, I liked a lot of the logic that went into it, and man if you expand on the groundwork they lay for you here and tweak some things around I think this would make an impressive demo for your portfolio. This is beyond your classic bootcamp demo app you build, this looks pretty polished imho. Plus it discusses core data which you will want to be familiar with because it has a lot of strengths when you need to sort and filter large collections. Its tough to grasp but I would say the author did a pretty good job at laying it out in chapter 7.One thing missing that I really wish was included was a sample widget app. The new widgets are almost exclusively built on swiftUI and I would have loved to see a widget built out with the same level of polish as these other apps. Overall through really great book and I would recommend this to anyone getting into SwiftUI.
Amazon Verified review Amazon
Anonymous Dec 21, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you want to learn SwiftUI, be it Obj-C master, Swift regular or total noob, this book will get you on the right track to create a bunch of different iOS apps with SwiftUI. Once you master the basics and the concepts through this book you'll be writing your own book. Love the chapters on Core Data and Combine. If you're building apps on your own those two chapters will be incredibly important. They're well written and the code is easily understood and explained.
Amazon Verified review Amazon
Juan Catalan Dec 22, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is written for intermediate iOS developers who are proficient with Xcode and Swift 5 and want to learn SwiftUI from scratch. SwiftUI is one of the must have skills to be successful in iOS development. If you do not have iOS development experience, you will not be able to follow the book and should learn Swift first.What I like the most about this book is the novel approach of teaching the SwiftUI framework by building six beautifully designed apps. Most technical books focus on teaching the technology thru sample code or very simple apps. However, in this book, Craig Clayton creates very complex apps from scratch, with very detailed user interfaces. If you code the apps in the book, you will learn SwiftUI and how to integrate this technology with other iOS frameworks to create App Store ready apps.The book follows a gradual approach and, as you progress thru the chapters, the apps and the code get more complex. The code in the book is very accurate and functional. I have spent a few days reading the book and I have downloaded the code from the companion GitHub repository. All the code listed in the book is in the repository. For each chapter in the book, the repository includes design files, a starter project, a completed project and the solutions to the code challenges. I have verified that the completed projects for each chapter build in Xcode without issues.SwiftUI is the core framework taught in this book, but I’d like to give a special mention to the chapter about CloudKit. The author provides step-by-step instructions on how to configure Cloudkit using the CloudKit Dashboard. In the app, there is code to populate the CloudKit database and if you follow all the steps correctly the app will pull the information from iCloud and display it in the app. Very impressive.In summary, this is an excellent book to learn SwiftUI by building real apps. The apps have a very detailed user interface, and the code is very well organized. The book provides detailed explanations of the code and step-by-step guides to configure any extra tools used.I am a professional iOS developer with more than 10 years of development experience. I have contributed to more than 30 published apps in the App Store, some of them with millions of users.Disclaimer: I was contacted by PackT to publish a review of this book, but I did not receive any compensation for it. The opinions are my own.
Amazon Verified review Amazon
Giovanni Noa Dec 13, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've really enjoyed SwiftUI Projects so far. I have been looking for a resource to understand how to use Core Data in my apps (have struggled with it for a while now) and I learned a lot from this book's chapters that build with it. You also get to build apps using Combine. Along with building for iPad and WatchOS, I think this is a solid book for any iOS developer looking to ship some apps, build various layouts in SwiftUI, or learn the new Apple frameworks.
Amazon Verified review Amazon
Paul A Dec 29, 2020
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The approach of the book is to walk you through building apps with SwiftUI. It's accessible, and the end result is good. The explanations are clear - you never feel overwhelmed.There are issues with some references in the book - the worst being 3 pages about a view that has been removed from the source code, and from the rest of the book. They're not huge issues, but they're pretty common.The formatting does make it difficult to follow the code at times, but that's pretty common for e-books on a tablet?I like that design isn't an afterthought and the book walks you through from having the assets from a designer and turning it into code.I'd definitely recommend this book, and would love to see another!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.