Hi everyone,
I want to perform the tutorial from video WWDC19 - 204. Here is an example of building the "Rooms" application. At 11 minutes, the author of the video, Jacob Xiao, shows how he performs the extract subview operation. But when I try to repeat this operation an error occurs - Cannot find 'room' in scope.
My code and code of Jacob Xiao are the same.
import SwiftUI
struct ContentView: View {
var rooms: [Room] = []
var body: some View {
NavigationView {
List(rooms) { room in
ExtractedView()
}
.navigationBarTitle(Text("Rooms"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(rooms: testData)
}
}
struct ExtractedView: View {
var body: some View {
NavigationLink(
destination: Text(room.name)) { // Cannot find 'room' in scope
Image(room.thumbnailName)
.cornerRadius(8)
VStack(alignment: .leading) {
Text(room.name)
Text("\(room.capacity) people")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
}
}
I think the reason is that SwiftUI on my computer is a newer version, so some of the previous functions may not work.
Could you tell me how to perform this subview extract operation today?