29.4 Adding the Car Structure
Now that the JSON file has been added to the project, a structure needs to be declared to represent each car model. Add a new Swift file to the project by selecting the File -> New -> File… menu option, selecting Swift File in the template dialog and clicking on the Next button. On the subsequent screen, name the file Car.swift before clicking on the Create button.
Once created, the new file will load into the code editor where it needs to be modified so that it reads as follows:
import SwiftUI
struct Car : Codable, Identifiable {
var id: String
var name: String
var description: String
var isHybrid: Bool
var imageName: String
}
As we can see, the structure contains a property for each field in the JSON file and is declared as...