【问题标题】:AppStore update and RealmAppStore 更新和 Realm
【发布时间】:2016-12-27 08:59:38
【问题描述】:

我在 Appstore 中有基于 Realm 移动数据库的应用程序。我想准备1.1版。更新会删除用户本地数据库中的所有数据吗?

【问题讨论】:

    标签: ios database app-store realm


    【解决方案1】:

    升级不会删除您当前数据库中的任何内容。迁移是自动的。如果您需要更改当前模型中的一个或多个字段,则需要升级数据库架构版本。将此代码放入 AppDelegate 中的 application:didFinishLaunchingWithOptions: 方法中:

        //Realm migration
        let config = Realm.Configuration(
            schemaVersion: 2, //here's the schema version you need to change
            migrationBlock: { migration, oldSchemaVersion in
                if (oldSchemaVersion < 2) {
                     //if you want to perform particular tasks
                     //while migrating, place your code here.
                }
        })
        Realm.Configuration.defaultConfiguration = config
        _ = try! Realm()
    

    【讨论】:

      【解决方案2】:

      绝对不会,它不会删除现有的数据库,这就是 Realm 支持自动/自定义迁移的原因。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-12
        相关资源
        最近更新 更多