向 Realm 对象添加属性时如何进行迁移

问题描述 投票:0回答:2

我收到如下崩溃报告:


Migration is required due to the following errors: - Property 'UserProfile.interfaceLanguage' has been added.

我了解一般如何执行迁移,但我不知道添加属性时需要什么。

interfaceLanguage
并不是应用程序工作所必需的,它最终会从服务器获取。我想我可以在迁移过程中将其设置为某个值,但这似乎有点毫无意义。

此外,我认为这种情况是默认处理的:https://realm.io/docs/swift/latest/#migrations

if(旧架构版本< 1) { // Nothing to do! // Realm will automatically detect new properties and removed properties // And will update the schema on disk automatically }

objective-c realm realm-migration
2个回答
3
投票

添加属性时,您无需在迁移块中执行任何操作,Realm 会自动进行迁移。您所要做的就是将架构版本增加 1,并增加

if (oldSchemaVersion < 1)
中的数字 (1)。


0
投票

您最终找到解决方案了吗?我们在添加可选属性时遇到了同样的问题。文档说这些类型的附加更改是自动执行的。

© www.soinside.com 2019 - 2024. All rights reserved.