Introduction |
|
1 | (1) |
About This Book |
|
1 | (1) |
Foolish Assumptions |
|
2 | (1) |
Icons Used in This Book |
|
2 | (1) |
Beyond the Book |
|
3 | (1) |
Where to Go from Here |
|
3 | (2) |
|
PART 1 GETTING STARTED WITH SWIFT ANDSWIFTUI |
|
|
5 | (56) |
|
Chapter 1 Introducing SwiftUI |
|
|
7 | (18) |
|
Understanding What SwiftUI Is |
|
|
7 | (4) |
|
|
11 | (10) |
|
|
12 | (2) |
|
Automatically previewing your user interface using the canvas |
|
|
14 | (4) |
|
Working with Live Preview |
|
|
18 | (1) |
|
Generating different previews |
|
|
19 | (2) |
|
|
21 | (4) |
|
|
22 | (1) |
|
|
22 | (1) |
|
|
23 | (2) |
|
Chapter 2 Basics of the Swift Programming Language |
|
|
25 | (36) |
|
|
26 | (2) |
|
|
26 | (1) |
|
|
27 | (1) |
|
|
27 | (1) |
|
|
27 | (1) |
|
|
28 | (2) |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
30 | (2) |
|
Retrieving elements from an array |
|
|
31 | (1) |
|
Inserting elements into an array |
|
|
31 | (1) |
|
Modifying elements in an array |
|
|
31 | (1) |
|
Appending elements to an array |
|
|
31 | (1) |
|
Removing elements from an array |
|
|
32 | (1) |
|
|
32 | (1) |
|
Retrieving elements from a dictionary |
|
|
32 | (1) |
|
Modifying an item in a dictionary |
|
|
33 | (1) |
|
Removing an item from a dictionary |
|
|
33 | (1) |
|
|
33 | (5) |
|
Working with implicitly unwrapped optionals |
|
|
35 | (1) |
|
|
36 | (1) |
|
Unwrapping optionals using'? |
|
|
36 | (1) |
|
Using the nil coalescing operator |
|
|
37 | (1) |
|
|
38 | (1) |
|
Understanding input parameters |
|
|
38 | (1) |
|
|
39 | (1) |
|
|
39 | (2) |
|
|
40 | (1) |
|
Ternary conditional operator |
|
|
40 | (1) |
|
|
40 | (1) |
|
|
41 | (2) |
|
|
42 | (1) |
|
|
42 | (1) |
|
|
42 | (1) |
|
Control transfer statements |
|
|
42 | (1) |
|
|
43 | (1) |
|
|
43 | (4) |
|
|
44 | (1) |
|
Structures as value types |
|
|
45 | (2) |
|
|
47 | (4) |
|
|
47 | (1) |
|
|
47 | (2) |
|
|
49 | (1) |
|
Trying out the self property |
|
|
50 | (1) |
|
|
51 | (4) |
|
|
51 | (1) |
|
Using functions as closures |
|
|
52 | (1) |
|
Assigning closures to variables |
|
|
52 | (1) |
|
|
53 | (1) |
|
Understanding type inference |
|
|
53 | (1) |
|
Using shorthand argument names |
|
|
54 | (1) |
|
Working with the operator function |
|
|
54 | (1) |
|
|
55 | (1) |
|
|
55 | (6) |
|
Defining and using a protocol |
|
|
56 | (1) |
|
|
56 | (1) |
|
Using the Codable protocol |
|
|
57 | (2) |
|
|
59 | (2) |
|
PART 2 UNDERSTANDING THE BASICS OF SWIFTUI |
|
|
61 | (144) |
|
Chapter 3 Getting Started with the Basics of SwiftUI |
|
|
63 | (24) |
|
Taking a Look at SwiftUI Views |
|
|
63 | (7) |
|
Conforming to the View protocol |
|
|
64 | (2) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
67 | (3) |
|
|
70 | (5) |
|
Using modifiers on the Image view |
|
|
72 | (1) |
|
|
73 | (2) |
|
|
75 | (3) |
|
|
76 | (1) |
|
|
77 | (1) |
|
|
78 | (7) |
|
|
79 | (1) |
|
|
80 | (5) |
|
Putting on the Finishing Touches |
|
|
85 | (2) |
|
Chapter 4 Handling User Inputs and Custom Views |
|
|
87 | (26) |
|
|
87 | (16) |
|
|
88 | (4) |
|
|
92 | (1) |
|
|
93 | (1) |
|
|
94 | (4) |
|
|
98 | (2) |
|
|
100 | (3) |
|
|
103 | (10) |
|
Composing the custom view |
|
|
104 | (7) |
|
|
111 | (2) |
|
Chapter 5 Displaying Lists of Items |
|
|
113 | (30) |
|
Using the List View to Display Items |
|
|
113 | (7) |
|
|
114 | (2) |
|
Adding rows programmatically |
|
|
116 | (3) |
|
Alternative way to generate rows in a List view |
|
|
119 | (1) |
|
Displaying the List within a NavigationView |
|
|
120 | (13) |
|
Making the items tappable |
|
|
121 | (2) |
|
|
123 | (2) |
|
Using the Identifiable protocol |
|
|
125 | (1) |
|
|
126 | (2) |
|
|
128 | (2) |
|
|
130 | (3) |
|
|
133 | (5) |
|
Displaying sections from a dictionary |
|
|
134 | (2) |
|
Changing the style of the List view |
|
|
136 | (2) |
|
Previewing in Light and Dark Modes |
|
|
138 | (5) |
|
|
138 | (1) |
|
|
139 | (4) |
|
Chapter 6 Creating Navigation and Tabbed Applications |
|
|
143 | (30) |
|
|
144 | (23) |
|
Working with the two key views in navigation-style apps |
|
|
145 | (3) |
|
|
148 | (1) |
|
Navigating programmatically |
|
|
149 | (2) |
|
Creating a news reader application |
|
|
151 | (16) |
|
Creating Tabbed Applications |
|
|
167 | (6) |
|
|
168 | (1) |
|
Selecting TabViews programmatically |
|
|
169 | (4) |
|
Chapter 7 Formatting Your User Interface |
|
|
173 | (32) |
|
Laying Out Views Using Stacks |
|
|
173 | (22) |
|
|
174 | (12) |
|
|
186 | (4) |
|
|
190 | (5) |
|
|
195 | (10) |
|
|
198 | (2) |
|
|
200 | (3) |
|
|
203 | (2) |
|
PART 3 EXPLORING WITH SWIFTUI IN MORE DETAIL |
|
|
205 | (58) |
|
Chapter 3 Understanding State Management in SwiftUI |
|
|
207 | (28) |
|
|
207 | (2) |
|
Maintaining State Using State Variables |
|
|
209 | (4) |
|
|
213 | (5) |
|
Managing State from External Objects |
|
|
218 | (5) |
|
Using the ObservableObject protocol and Published |
|
|
219 | (2) |
|
Using the @ObservedObject |
|
|
221 | (2) |
|
|
223 | (5) |
|
Accessing Built-in Environment Variables |
|
|
228 | (7) |
|
Defining your own environment keys |
|
|
230 | (1) |
|
Using your own environment keys |
|
|
231 | (4) |
|
Chapter 9 Using Legacy UIKit Views and View Controllers in SwiftUI |
|
|
235 | (28) |
|
|
236 | (11) |
|
Understanding the UIKit View Controller life cycle |
|
|
237 | (2) |
|
Understanding the SwiftUI view life cycle |
|
|
239 | (8) |
|
Using the UIViewRepresentable Protocol for UIKit Views |
|
|
247 | (6) |
|
|
248 | (3) |
|
|
251 | (2) |
|
Using the UIViewControllerRepresentable Protocol for UIKit View Controllers |
|
|
253 | (10) |
|
Creating the ImagePickerViewController |
|
|
254 | (2) |
|
Handling events using coordinators |
|
|
256 | (2) |
|
Defining the methods in the Coordinator class |
|
|
258 | (2) |
|
Using the updated ImagePickerViewController |
|
|
260 | (3) |
|
PART 4 PERFORMING ANIMATIONS AND DRAWINGS |
|
|
263 | (88) |
|
Chapter 10 Drawings and Special Effects |
|
|
265 | (34) |
|
Drawing Using the Five Built-in Shapes |
|
|
266 | (11) |
|
|
266 | (4) |
|
|
270 | (3) |
|
|
273 | (1) |
|
|
274 | (1) |
|
|
275 | (2) |
|
Clipping with the Basic Shapes |
|
|
277 | (4) |
|
|
281 | (11) |
|
|
283 | (1) |
|
|
284 | (2) |
|
|
286 | (1) |
|
|
287 | (2) |
|
Combining fill and stroke |
|
|
289 | (3) |
|
Using Special Effects in SwiftUI |
|
|
292 | (7) |
|
|
292 | (5) |
|
|
297 | (1) |
|
|
298 | (1) |
|
Chapter 11 Performing Animations in SwiftUI |
|
|
299 | (24) |
|
Understanding How to Animate |
|
|
299 | (8) |
|
Specifying the type of animation |
|
|
303 | (1) |
|
|
303 | (1) |
|
|
304 | (3) |
|
Performing Your Own Animation |
|
|
307 | (7) |
|
|
307 | (2) |
|
|
309 | (5) |
|
Creating a Custom Progress Indicator |
|
|
314 | (9) |
|
Indeterminate progress indicator |
|
|
314 | (4) |
|
Determinate progress indicator |
|
|
318 | (5) |
|
Chapter 12 Creating a Complete Project |
|
|
323 | (28) |
|
Understanding What the App Does |
|
|
323 | (2) |
|
|
325 | (21) |
|
|
325 | (3) |
|
Defining the news sources and observable objects |
|
|
328 | (2) |
|
|
330 | (1) |
|
Displaying the news headlines |
|
|
331 | (3) |
|
|
334 | (2) |
|
|
336 | (2) |
|
|
338 | (1) |
|
Creating the preferences view |
|
|
339 | (5) |
|
Persisting the user's preferences |
|
|
344 | (2) |
|
|
346 | (5) |
|
|
351 | (28) |
|
Chapter 13 Ten SwiftUI Tips and Tricks |
|
|
353 | (22) |
|
|
353 | (1) |
|
Implementing Localization |
|
|
354 | (4) |
|
|
358 | (2) |
|
Creating Custom Modifiers |
|
|
360 | (2) |
|
Displaying Multiple Alerts |
|
|
362 | (1) |
|
|
363 | (1) |
|
Previewing Using Different Devices |
|
|
364 | (4) |
|
Dark Mode Only Works On NavigationView |
|
|
368 | (2) |
|
|
370 | (3) |
|
Displaying a Context Menu |
|
|
373 | (2) |
|
Chapter 14 Ten Great SwiftUI Resources |
|
|
375 | (4) |
|
|
375 | (1) |
|
|
376 | (1) |
|
|
376 | (1) |
|
|
376 | (1) |
|
|
376 | (1) |
|
|
377 | (1) |
|
|
377 | (1) |
|
|
377 | (1) |
|
|
377 | (1) |
|
|
378 | (1) |
Appendix: Code Snippets For Common Swiftui Views |
|
379 | (8) |
Index |
|
387 | |