Closed jdanthinne closed 7 years ago
Hi @jdanthinne, thanks for reaching out. I'll have someone review what you've shared and respond with a solution or follow-up questions soon. Cheers! :-)
Thanks!
My guess is that if oldSchemaVersion < 2 {
applies to both versions 0 and 1, so it's running for the 0-2 migration and not finding the hasDate
property on the version-0 objects. I think the easiest way to solve your problem is to move your if statement into the migration block and make it run only when migrating from version 1 to a later version.
migration.enumerateObjects(ofType: Sheet.className(), { (oldObject, newObject) in
if oldSchemaVersion == 1 {
newObject!["hasDate"] = oldObject!["dateStart"] != nil
}
})
You might also want to check out our multi version migration example.
That was simple. Brilliant. Thanks.
Goals
I'm trying to write a correct migration path for the following model
Schema version 0
Schema version 1
Schema version 2
My migration block is
Expected Results
A correct migration…
Actual Results
For apps migrating from schema version 1 to 2, everything seems ok, because dateStart exists. For apps migrating from schema version 0 to 2, its breaks…
Version of Realm and Tooling
Realm version: 2.4.2 Xcode version: 8.2.1 iOS/OSX version: 10.2/10.12.3 Dependency manager + version: Carthage 0.18.1