I modified a model within my code changing a field from type Int to an enum value type ModelType.
Since doing this my app will not build! I get the message:
/var/folders/x1/pptzf9797576q9pzdzvr2qqh0000gn/T/swift-generated-sources/@__swiftmacro_7TripApp7JourneyC10travelMode18_PersistedPropertyfMa_.swift:4:23 Instance method 'setValue(forKey:to:)' requires that 'TravelMode' conform to 'PersistentModel'
What have I done wrong? I followed one of the several examples that are available.
The model is:
enum TravelMode: String, CaseIterable, Identifiable {
case undefined, flight, car, train, hike, sail, other
var id: Self { self }
}
@Model
class Journey: Identifiable, Hashable {
var trip: String
var name: String
var date: Date
var latitudeFrom: Double
var longitudeFrom: Double
var latitudeTo: Double
var longitudeTo: Double
var travelMode: TravelMode?
var details: String
It is used as follows when assigning the value:
travelMode: .flight,
and its associated picker lookalike:
Picker("Travel Mode", selection: $selectedTravelMode) {
ForEach(TravelMode.allCases) { travelMode in
Text(travelMode.rawValue.capitalized)
}
}
Any suggestions?
Your enum must conform to
Codablein order for it to conform toPersistentModel