【发布时间】:2017-05-14 18:18:41
【问题描述】:
在领域文档中,我看到了迁移的代码示例
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
然后它说使用let realm = try! Realm() 来获取领域实例。但是,在我们的应用程序中,我们使用自己的领域配置,例如
let realm = try! Realm(configuration: RealmConfig.getConfig(typeURL: .userData)!)
除了.userData,我们还有一些不同的配置。我的问题是,如何使用这些非默认配置进行迁移?代码示例实际上只显示了如何设置对我的使用无关紧要的默认配置。我找不到类似的东西
Realm.Configuration.userData = config
是否存在我想念的这种东西?或者我还有其他方法可以解决这个问题吗?
【问题讨论】: