From the course: Make SwiftUI Playgrounds Applications
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Optional values - Swift Tutorial
From the course: Make SwiftUI Playgrounds Applications
Optional values
- [Steven] Our app is almost perfect. There's one small detail I'd like to change in our app. We used to have the surfer image when we hadn't selected a pizza. Now we have a default pizza. What I'd like is that surfer back until we select a pizza, a state that we says that we haven't selected a pizza yet, but that needs a value that means there's no value in selected pizza. Everything we've done so far has a value. How do you have that value that means no value? That is what optional variables are for. Optionals add a special value called nil. Nil stands for no value yet in this variable. I have to tell the declaration that this will be an optional value and then treat that optional differently than regular variables to detect the nil condition. If a nil is used as a value, an error occurs. Let's change selected pizza to a value of nil. So first of all, let's go hide the preview so we don't have to worry about it for a…
Contents
-
-
-
(Locked)
More on the view hierarchy12m 11s
-
(Locked)
Formatted numbers8m 23s
-
(Locked)
Computed properties6m 7s
-
(Locked)
Arrays9m 54s
-
(Locked)
For loops9m 42s
-
(Locked)
Use ForEach in SwiftUI8m 32s
-
(Locked)
Protocols, Hashable, and Identifiable3m 56s
-
(Locked)
Importing models and assets8m 27s
-
(Locked)
Adapting models8m 43s
-
(Locked)
Scroll view and list6m 34s
-
Work with @State and toggle buttons8m 43s
-
(Locked)
Make Button arrays7m 13s
-
(Locked)
Work with @Binding5m 59s
-
(Locked)
Enumeration types8m 45s
-
(Locked)
Selection from lists4m 21s
-
(Locked)
Optional values6m 10s
-
(Locked)
-