1
我开始使用Realm,但没有找到任何有关如何处理模型版本的信息。例如,我想在我的应用程序的下一个版本中添加/删除一些属性。很多预先感谢!Did Realm是否支持模型版本?
我开始使用Realm,但没有找到任何有关如何处理模型版本的信息。例如,我想在我的应用程序的下一个版本中添加/删除一些属性。很多预先感谢!Did Realm是否支持模型版本?
以下是有关迁移的领域文档页面:https://realm.io/docs/swift/latest/#migrations。
如果您在Realm.Configuration中指定了更高版本的架构版本号,则会自动迁移已删除和添加的属性。如果要执行实际迁移,则只需使用迁移块,如将属性映射到另一个。
let realmConfiguration = Realm.Configuration(
path: nil,
inMemoryIdentifier: nil,
encryptionKey: nil,
readOnly: false,
schemaVersion: schemaVersionNumber,
migrationBlock: migrationBlock,
objectTypes: nil)
do {
realm = try Realm(configuration: realmConfiguration)
print("[REALM] Path: \(realm.path)")
} catch let error as NSError {
fatalError("Error opening realm: \(error)")
}