Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SwiftUI Projects

You're reading from   SwiftUI Projects Build six real-world, cross-platform mobile applications using Swift, Xcode 12, and SwiftUI

Arrow left icon
Product type Paperback
Published in Dec 2020
Publisher Packt
ISBN-13 9781839214660
Length 410 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Craig Clayton Craig Clayton
Author Profile Icon Craig Clayton
Craig Clayton
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

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

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...
You have been reading a chapter from
SwiftUI Projects
Published in: Dec 2020
Publisher: Packt
ISBN-13: 9781839214660
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime