【问题标题】:Realm Migration Error: 'RLMException': 'Property 'RecipeStep.recipeId' does not exist'领域迁移错误:'RLMException':'属性'RecipeStep.recipeId'不存在'
【发布时间】:2021-02-05 15:46:49
【问题描述】:

我在 Realm 迁移期间遇到了问题。错误消息说该属性不存在,但这是我的新对象的样子:

class RecipeStep: Object {
   @objc dynamic var recipeId: Int = 0
   let stepNumber = RealmOptional<Int>()
   @objc dynamic var stepText: String? = nil
}

这是旧对象架构的样子:

class RecipeStep: Object {
   let recipeId = RealmOptional<Int>()
   let stepNumber = RealmOptional<Int>()
   @objc dynamic var stepText: String? = nil
}

如您所见,唯一的变化是 recipeId 的类型:将 RealmOptional 转换为 Int。这是我用来执行此操作的迁移块:

migration.enumerateObjects(ofType: RecipeStep.className()) { oldObject, newObject in
               if let recipeStepRecipeId = oldObject?["recipeId"] as? Int {
                  newObject?["recipeId"] = recipeStepRecipeId
               }
            }

我做错了什么?

【问题讨论】:

    标签: ios swift realm realm-migration


    【解决方案1】:

    这原来是旧版本 Realm (v5.4.5) 中的一个错误。我更新到版本 10.0.0 并且这个问题得到了解决。迁移成功完成。我的代码中没有任何更改。

    我正在使用 Xcode 12,为 iOS 13 构建。

    SO thread 上找到了关于类似听起来错误的讨论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多