29.6 Adding the Data Store
When the user interface has been designed, the List view will rely on an observable object to ensure that the latest data is always displayed to the user. So far, we have a Car structure and an array of Car objects loaded from the JSON file to act as a data source for the project. The last step in getting the data ready for use in the app is to add a data store structure. This structure will need to contain a published property which can be observed by the user interface to keep the List view up to date. Add another Swift file to the project, this time named CarStore.swift, and implement the class as follows:
import SwiftUI
import Combine
class CarStore : ObservableObject {
@Published var cars: [Car]
init (cars: [Car] = []) {
self.cars = cars
}
}
...