ios - Realm 是否支持模型版本?

标签 ios objective-c database swift realm

我开始使用 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/

相关文章:

ios - 当应用程序处于后台时播放声音

iOS:重用 TabBarController 并删除旧 Controller 的一些选项卡

ios - UIApplication.shared.isNetworkActivityIndi​​catorVisible 设置为 false 时崩溃

java - 在客户端计算机上为 Java 桌面应用程序 (swing) 创建数据库

php - 数据库规范化和数据输入(管理后端)

ios - 如何从 Storyboard 文件中获取现有的 Controller 对象?

ios - 在 uiscrollview 中滑动不能正常工作

iphone - 如何从 UIWebview 或 dealloc UIWebview 中删除缓存

ios - iOS-处理多个复选框

c# - ListBox 已设置数据源但刷新不执行任何操作