我开始使用 Realm,但我没有找到任何关于如何处理模型版本的信息。例如,我想在我的应用程序的下一个版本中添加/删除一些属性。非常感谢!
最佳答案
这是关于迁移的 Realm 文档页面:https://realm.io/docs/swift/latest/#migrations .
如果您在 Realm.Configuration 中指定更高的架构版本号,则删除和添加的属性将自动迁移。如果您想进行真正的迁移,例如将一个属性映射到另一个属性,您只需要使用迁移 block 。
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)")
}
关于ios - Realm 是否支持模型版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36278971/