【问题标题】:How to perform migration when adding a property to a Realm object向 Realm 对象添加属性时如何执行迁移
【发布时间】:2017-05-17 04:17:34
【问题描述】:

我收到如下崩溃报告: Migration is required due to the following errors: - Property 'UserProfile.interfaceLanguage' has been added.

我大致了解如何执行迁移,但我不知道添加属性时需要什么。 interfaceLanguage 不是应用程序运行的严格要求,最终会从服务器获取。我想我可以在迁移期间将其设置为某个值,但这似乎有点毫无意义。

另外,我还以为这个case默认处理了:https://realm.io/docs/swift/latest/#migrations

if (oldSchemaVersion

【问题讨论】:

    标签: objective-c realm realm-migration


    【解决方案1】:

    添加属性时,您无需在迁移块中执行任何操作,Realm 会自动执行迁移。您所要做的就是将您的架构版本增加一,并将if (oldSchemaVersion < 1) 中的数字 (1) 也增加。

    【讨论】:

    • 我在这里遇到崩溃的事实意味着 1. 实际上需要非自动迁移或 2. 领域中存在错误。我看不出在迁移中添加一个空的 if 语句可以解决任何问题。
    猜你喜欢
    • 2016-03-20
    • 2011-12-10
    • 1970-01-01
    • 2021-08-27
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多