From 4c2811246d17146b13414787b142ad1db3394561 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Tue, 16 May 2023 22:18:11 +0300 Subject: [PATCH] Make powerHp optional --- AutoCat/AppDelegate.swift | 2 +- AutoCatCore/Models/Vehicle.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index 600061c..f8ece8a 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -26,7 +26,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( - schemaVersion: 39, + schemaVersion: 40, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 31 { migration.enumerateObjects(ofType: "Vehicle") { old, new in diff --git a/AutoCatCore/Models/Vehicle.swift b/AutoCatCore/Models/Vehicle.swift index abb7fbd..658a2c0 100644 --- a/AutoCatCore/Models/Vehicle.swift +++ b/AutoCatCore/Models/Vehicle.swift @@ -43,7 +43,7 @@ public class VehicleModel: Object, Decodable, Cloneable { public class VehicleEngine: Object, Decodable, Cloneable { @Persisted public var number: String? @Persisted public var volume: Int? = 0 - @Persisted public var powerHp: Float = 0 + @Persisted public var powerHp: Float? = 0 @Persisted public var powerKw: Float? = 0 @Persisted public var fuelType: String? @@ -55,7 +55,7 @@ public class VehicleEngine: Object, Decodable, Cloneable { let container = try decoder.container(keyedBy: CodingKeys.self) self.number = try container.decodeIfPresent(String.self, forKey: .number) self.volume = try container.decodeIfPresent(Int.self, forKey: .volume) - self.powerHp = try container.decode(Float.self, forKey: .powerHp) + self.powerHp = try container.decodeIfPresent(Float.self, forKey: .powerHp) self.powerKw = try container.decodeIfPresent(Float.self, forKey: .powerKw) self.fuelType = try container.decodeIfPresent(String.self, forKey: .fuelType) }