From the course: iPadOS 13 Development Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Setting a default selection

Setting a default selection - iOS Tutorial

From the course: iPadOS 13 Development Essential Training

Start my 1-month free trial

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…

Contents