Adding model objects and configuring navigation
You now have a view that can be used to display the details of a restaurant. You’ll use this view as a cell in a SwiftUI list, which is a container that presents data in a single column. You’ll also configure model objects to populate this list. Follow these steps.
- Command + click on the
HStack
view and choose Embed in List to display a list containing five cells in the canvas, and remove theSpacer
objects:
Figure 24.13: Editor area showing pop-up menu with Embed in List selected
- Verify that your code looks like this:
struct ContentView: View { var body: some View { List(0 ..<5) { item in VStack{ Text("The Tap Trailhouse") .font(.headline) Text("Brewery, Burgers, American") .font(.subheadline) .foregroundColor(.secondary) Image(systemName: "globe"...