In Local Database we moved from Realm (Obj-C) to RealmSwift. After migration we have an issue in local db like all the properties were declared as Optional in Obj-C. Whereas, we used non-optional in swift db. now, we are forced to migrate entire database to new one.
we can't make manually migrate each property. like,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
migration.enumerateObjects(ofType: User.className()) { oldObject, newObject in
newObject!["Id"] = oldObject!["Id"]
}
}
we need a function to do migration for each property without hardcoding. Handle respective datatypes Dynamically as required.
We are trying to make dynamic function.
Here is the dynamic function for realm migration,