I am using Realm as Mobile database in my running app. I have uploaded the app in App Store. But after uploading in the next version I had to change some data model of Realm Class. For this I use migration.
let config = Realm.Configuration(
schemaVersion: 2,
let config = Realm.Configuration(
if (oldSchemaVersion < 2) {
migration.enumerateObjects(ofType: CarRealm.className(), { (oldObject, newObject) in
})
migration.enumerateObjects(ofType: CarService.className(), { (oldObject, newObject) in
})
}
})
Realm.Configuration.defaultConfiguration = config
do {
_ = try Realm()
} catch _ as NSError {
// print error
}
}
But problem is that the user who are using the past version of this app (download from App Store) there app is crashing. When I debug I found the error for the version. Provided schema version 1 is less than last set version 2.
This error encounter when try to access the realm database like that
if MoreUses.sharedInstance().realm.objects(HyperWare.self).count != 0{
}
What is the solution ?