Adding migration for event identifiers

This commit is contained in:
Selim Mustafaev 2021-09-26 20:02:31 +03:00
parent d656cc1698
commit 710421d5bb

View File

@ -133,6 +133,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}
if oldSchemaVersion <= 34 {
var ids: Set<String> = 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