因此,我一直在尝试迁移Realm模式,但似乎无法执行以下操作。
在中oldSchema
,我具有以下内容:
class Period: Object {
dynamic var weekday: Weekday! // this is just another Realm Object
}
在中newSchema
,我试图将“工作日”移到“工作日”列表中。
class Period: Object {
let weekdays: List<Weekday> = List<Weekday>()
}
执行Realm迁移时,如何将weekday
对象从oldSchema
移至的weekdays
列表中newSchema
。
谢谢。
您可以在“Realm
配置”下运行迁移块。
Realm.Configuration.defaultConfiguration = Realm.Configuration(
schemaVersion: 2,
migrationBlock: { migration, oldSchemaVersion in
migration.enumerate(Period.className()) { oldObject, newObject in
// filter the versions where this change would take place
// if oldSchemaVersion < 1 {
// }...
newObject["weekdays"] = [oldObject["weekday"]]
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句