From the course: iPadOS 13 Development Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Setting a default selection - iOS Tutorial
From the course: iPadOS 13 Development Essential Training
Setting a default selection
- [Instructor] One of the things you may have noticed with our app so far is that there is no default selection. Let's take a look at creating a default selection here. So what I'm going to do is create a state variable right here and we'll call this selectedItem and that's going to be of the type Item and it's going to be optional. Then I'm going to set that equal to items, index, zero. Now when I do that I'm going to get an error and that says that I can't use items because it's not initialized yet. So what I can do here is just type static let items equal that and then this error should go away. Now in here it says static member items cannot be used on instance of type ContentView. And then it says insert ContentView dot. And we make that simple change and then we have that update that we want. So now what we need to do is, in our instantiation of NavigationLink, we're going to add two more parameters. The first one is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
SwiftUI basics4m 46s
-
Previewing multiple platforms in SwiftUI2m 53s
-
(Locked)
Using SwiftUI to create navigation4m 10s
-
(Locked)
Creating a SwiftUI navigation model3m 4s
-
(Locked)
Setting a default selection2m 58s
-
(Locked)
Working with unsupported views in SwiftUI2m 24s
-
(Locked)
Challenge: Add an image1m 43s
-
(Locked)
Solution: Add an image2m 44s
-
(Locked)
-
-
-
-
-