I am doing a migration which requires removing objects from the realm and replacing them with a different type.
In short, I used to have a single type, and am now creating a hierarchy, so BaseItem now needs to be a DerivedItem.
I'm not sure the best way to accomplish this.
Here's what I am going to try:
setSchemaVersion(kSchemaVersion, Realm.defaultPath, { migration, oldSchemaVersion in
if oldSchemaVersion == 0 {
let realm = Realm()
realm.write({ () -> Void in
old = oldObject!
if old["type"] as! Int == 1 {
let textItem = TextItem()
textItem.text = old["text"] as! String
copyBaseItemCommon(old, textItem)
realm.add(textItem)
realm.delete(newObject!)
}
})
Are those add and deletes the way to go?
UPDATE:
Tried this and the code deadlocks in line 3: let realm = Realm()
Anyone know what the technique for doing this type of migration is?