Reputation: 1
In the realm docs I see the code example for migrations
let 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: 1,
// 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 < 1) {
// 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
and then it says to use let realm = try! Realm()
to get the realm instance. However, in our application we are using our own realm configurations with something like
let realm = try! Realm(configuration: RealmConfig.getConfig(typeURL: .userData)!)
We have a few different configurations besides .userData
. My question is, how does one go about doing migrations with these non-default configurations? The code example really only shows how to set the default configuration which is insignificant for my use. I couldn't find anything like
Realm.Configuration.userData = config
Does something like this exist that I am missing? Or is there another way I'm supposed to go about this?
Upvotes: 0
Views: 227
Reputation: 7340
You can instantiate different Realm instances with different configurations like this:
let userDataConfiguration = Realm.Configuration(...)
let userDataRealm = try! Realm(configuration: userDataConfiguration)
Learn more in docs at https://realm.io/docs/swift/latest/#realms
Upvotes: 1