I recently did a pod update on my project and ever since that Im facing an issue with Realm. The code is as follows,
MyNetworkManager.sharedNetworkManager.performNetworkOperation(url: MyEndpoint().homepage(), httpmethod: .get, parameters: requestDict) { response in
let realm = try! Realm()
try! realm.write {
let JSON = response.result.value as AnyObject
realm.create(HomePageData.self, value: JSON, update: true)
}
The error shown is as follows,
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=io.realm Code=1 "Provided schema version 84 is less than last set
version 86." UserInfo={NSLocalizedDescription=Provided schema version 84 is
less than last set version 86., Error Code=1}
I read other answers on the same issue but didn't find anything similar. Im new to Realm in general, kindly let me know what is the best way to solve this.
Project Details :
You are install app old version on new version (downgrade)
This is what causes this problem just try to migrate your DB
var config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: 87,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 86) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
})
// Tell Realm to use this new configuration object for the default Realm
Realm.Configuration.defaultConfiguration = config