29.7 Designing the Content View
Select the ContentView.swift file and modify it as follows to add a state object binding to an instance of CarStore, passing through to its initializer the carData array created in the CarData.swift file:
import SwiftUI
struct ContentView: View {
@StateObject var carStore : CarStore = CarStore(cars: carData)
.
.
The content view is going to require a List view to display information about each car. Now that we have access to the array of cars via the carStore property, we can use a ForEach loop to display a row for each car model. The cell for each row will be implemented as an HStack containing an Image and a Text view, the content of which will be extracted from the carData array elements. Remaining in the ContentView.swift file, delete the existing “Hello, world” Text view and implement the list as follows:
.
.
var body: some View {
...