Learn SwiftUI

SwiftUI is the new and powerful interface toolkit that lets you design and build iOS, iPadOS, and macOS apps using decla

2,575 695 17MB

English Pages 304 Year 2020

Report DMCA / Copyright

DOWNLOAD FILE

Learn SwiftUI

Table of contents :
Cover......Page 1
Title Page......Page 2
Copyright and Credits......Page 3
Dedication......Page 4
About Packt......Page 5
Contributors......Page 6
Table of Contents......Page 8
Preface......Page 15
Chapter 1: Getting Started with SwiftUI......Page 20
Introducing Swift as a programming language......Page 21
Creating the UI programmatically......Page 24
Creating a UI via Interface Builder......Page 25
What is SwiftUI? ......Page 26
Tools and features......Page 28
When to use SwiftUI, and why......Page 29
Further reading......Page 30
Chapter 2: Understanding Declarative Syntax......Page 31
What is declarative syntax?......Page 32
Getting started with SwiftUI in Xcode......Page 33
Making a "Hello World" app......Page 35
Returning multiple views......Page 36
Modifiers......Page 37
Nesting syntax......Page 40
Grouping......Page 41
Imperative syntax......Page 42
Further reading......Page 43
Technical requirements......Page 44
MVVM overview......Page 45
MVVM in SwiftUI ......Page 46
Other architecture patterns......Page 47
Observable objects......Page 48
Publishing objects......Page 52
Further reading......Page 54
Technical requirements......Page 55
Creating our first project......Page 56
Navigator......Page 58
Scheme and device list......Page 59
Automatic Preview ......Page 60
Xcode Simulator......Page 61
Understanding Automatic Preview......Page 63
Understanding the Preview Provider......Page 67
Questions......Page 68
Further reading......Page 69
Chapter 5: Understanding Controls, Views, and Lists......Page 70
Text options......Page 71
Updating PreviewProvider......Page 74
A little more Text decoration......Page 75
Creating a custom view......Page 77
Working independently with our new custom view......Page 79
Adding more controls......Page 82
Buttons......Page 83
Images......Page 86
Segmented (picker) contols......Page 87
Summary......Page 89
Further reading......Page 90
Technical requirements......Page 91
Creating the recipe details View......Page 92
Updating our mock data......Page 95
App navigation......Page 97
Adding navigation to our ContentView......Page 98
Accessing with @EnvironmentObject......Page 101
Adding and injecting the @EnvironmentObject class......Page 102
Using @EnvironmentObject......Page 103
Using EnvironmentObject as a single source of truth......Page 104
EnvironmentObject best practices......Page 106
Mock EnvironmentObject......Page 107
Summary......Page 108
Further reading......Page 109
Technical requirements......Page 110
Implementing text and text fields......Page 111
Creating our first custom modifier......Page 113
Adding a button to the navigation bar......Page 117
Adding images from our library......Page 119
Creating our Image View......Page 120
Implementing our ImageHelper......Page 122
Implementing a UITextView wrapper......Page 124
Adding a country picker......Page 127
Persisting our image......Page 130
Persisting our data......Page 133
Making the save......Page 134
Questions......Page 135
Technical requirements......Page 136
Creating our network helper......Page 137
Invoking our network request......Page 138
Implementing UIViewRepresentable......Page 140
Customizing our UIViewRepresentable and coordinators......Page 141
Implementing UIViewControllerRepresentable......Page 144
Options for macOS......Page 147
Options for watchOS......Page 149
Questions......Page 150
Further reading......Page 151
Technical requirements......Page 152
Implementing MapKit......Page 153
Adding a MapKit View to SwiftUI......Page 154
Adding your first annotation (pin)......Page 157
Creating custom annotations......Page 160
Creating our MapLocationManager......Page 162
Hooking up our MapLocationManager to SwiftUI ......Page 164
Location permissions......Page 166
Updating our Helper classes......Page 171
Hooking up our MapView......Page 173
Adding an annotation callout accessory and filtering......Page 175
Adding a reset filter button......Page 179
Questions......Page 180
Further reading......Page 181
Technical requirements......Page 182
Project settings......Page 183
Portrait and landscape support......Page 184
Understanding assets......Page 186
iPadOS simulators......Page 188
Running on the simulator......Page 190
Initial support for list views ......Page 193
Other NavigationViewStyle options......Page 196
Making use of DoubleColumnNavigationViewStyle......Page 197
Improving our architecture with DoubleColumnNavigationViewStyle......Page 202
Cleaner navigation architecture......Page 204
Final check on our iPhone and iPad app......Page 206
Questions......Page 207
Further reading......Page 208
Chapter 11: SwiftUI on watchOS......Page 209
What is WatchKit?......Page 210
Extensions in watchOS......Page 211
Creating a watchOS project......Page 212
Updating our project......Page 213
Changes to our project......Page 215
Creating a List() view in watchOS......Page 218
Using our mock data......Page 219
Multiple screens in watchOS......Page 223
Adding multiple screens......Page 224
Passing data between our app and watchOS......Page 228
Initializing WatchConnectivity in iOS......Page 229
Sending data to watchOS......Page 231
Receiving data on watchOS......Page 232
Testing sendMessage() end to end......Page 234
Questions......Page 236
Further reading......Page 237
Technical requirements......Page 238
Basic UITableView implementation......Page 239
Basic SwiftUI List implementation......Page 243
UIKit – multiple Data Sources......Page 244
SwiftUI – handling Data Sources......Page 245
Simple decoration made easy......Page 246
Complex decoration made easy......Page 247
UIStackView......Page 249
Summary......Page 250
Questions......Page 251
Technical requirements......Page 252
Implicit animations......Page 253
Explicit animations......Page 255
.easeIn ......Page 256
.easeOut......Page 257
Springs......Page 258
.spring ......Page 259
Rotation......Page 260
Scaling......Page 262
Fading image......Page 264
Rotating the 3D action button......Page 265
Questions......Page 267
Further reading......Page 268
Technical requirements......Page 269
Invoking a basic transition......Page 270
Transition modifier options......Page 271
Moving views with transitions......Page 272
Asymmetric transitions......Page 273
Using asymmetric, combined, and inline animations together......Page 274
Transition validation......Page 275
Asymmetric transition – loading state......Page 276
Questions......Page 278
Chapter 15: Testing in SwiftUI......Page 279
Creating a UI test project......Page 280
Writing our very first UI Test......Page 282
Writing multiple UI Tests......Page 284
Nesting UI Tests......Page 285
Testing with assertions......Page 286
Creating a Unit Test project......Page 287
Writing our very first Unit Test......Page 288
Unit Testing conclusion......Page 289
Understanding breakpoints......Page 290
Inspecting variables......Page 291
Understanding the console window......Page 292
Instruments......Page 294
Analyze......Page 295
Further reading......Page 296
Other Books You May Enjoy......Page 297
Index......Page 300

Polecaj historie