@propertyWrapper
struct KilometersPerHour {
var wrappedValue: Measurement<UnitSpeed>
}
extension KilometersPerHour: Codable {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(Double.self)
wrappedValue = Measurement(
value: rawValue,
unit: .kilometersPerHour
)
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(wrappedValue.value)
}
}