0

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 ?

  • look this solution https://stackoverflow.com/questions/34781895/how-can-i-get-the-migration-to-run-before-the-app-starts-to-run-the-code – a.masri Apr 11 '18 at 12:12
  • this exception because , It seems you have access to the Realm in your code before the configuration – a.masri Apr 11 '18 at 12:15

0 Answers0