Swift Realm Property #39;*#39; has been added to latest object model MIGRATION(Swift Realm 属性“*已添加到最新的对象模型迁移中)
问题描述
我在 RLMObject 中添加了新的数组属性,并且
I have added new array attribute to the RLMObject and
public class Student: RLMObject {
dynamic var id = 0
dynamic var name = ""
dynamic var resultList = RLMArray(objectClassName:Result.className())
}
public class Result: RLMObject {
}
错误日志:
由于以下原因,对象类型学生"需要迁移错误:- 属性resultList"已添加到最新的对象模型中.
Migration is required for object type 'Student' due to the following errors: - Property 'resultList' has been added to latest object model.
尝试失败:
let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()
migration.enumerateObjects(Student.className()) { oldObject, newObject in
newObject!["resultList"] = RLMArray(objectClassName: Result.className())
}
let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()
print("Realm db current version: (configuration.schemaVersion)")
configuration.schemaVersion = 1
configuration.migrationBlock = {(migration:RLMMigration, oldSchemaVersion: UInt64) in
print("Realm db migration start")
if oldSchemaVersion < 1 {
print("Schema version: 1 - Rename fields")
migration.enumerateObjects(Student.className()) { oldObject, newObject in
newObject!["creationDate"] = oldObject!["createdAt"]
newObject!["modifiedDate"] = oldObject!["updatedAt"]
}
}
print("Realm db migration finish")
}
RLMRealmConfiguration.setDefaultConfiguration(configuration)
let realm = RLMRealm.defaultRealm()
解决方案:
将您的版本更新为 +1
update your version to +1
configuration.schemaVersion += 1
推荐答案
你必须增加你的 schemaVersion 并在你的 RLMRealmConfiguration 上提供一个 migrationBlock>.在那里你可以迁移表.但是在您的特定情况下,您不需要它.可以自动处理属性的添加.你仍然需要一个空块.
You have to incremented your schemaVersion and provide a migrationBlock on your RLMRealmConfiguration. In there you can migrate tables. But you don't need that in your specific case here. The addition of properties can be handled automatically. You'll still need an empty block.
let config = RLMRealmConfiguration.defaultConfiguration()
config.schemaVersion = 1
config.migrationBlock = { (migration, oldSchemaVersion) in
// nothing to do
}
RLMRealmConfiguration.setDefaultConfiguration(config)
这篇关于Swift Realm 属性“*"已添加到最新的对象模型迁移中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swift Realm 属性“*"已添加到最新的对象模型迁移中
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
