diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index bca5977..46e6990 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -133,6 +133,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } } } + + if oldSchemaVersion <= 34 { + var ids: Set = Set() + migration.enumerateObjects(ofType: "VehicleEvent") { old, new in + guard let oldId = old?["id"] as? String? else { return } + + var newId = oldId ?? UUID().uuidString + if ids.contains(newId) { + newId = UUID().uuidString + } + ids.insert(newId) + + new?["id"] = newId + } + } }) Realm.Configuration.defaultConfiguration = config