I'm working on updating an existing app. I have 3 entities in core data that need to be changed in a new dataModel.
The first 2 (changing a string to a double) are working flawlessly in my NSEntityMigrationPolicy.
The last one just changes the entity "name" in the first dataModel (String, optional) to "name" in the revised dataModel (String, not optional).
Because I have the first type of change, I have to use the custom migration policy, so I can't have it convert the optional to non-optional automatically (lightweight data migration).
Steps taken
1. In dataModel2, uncheck optional for "name"
2. In my Event class, change "name" from optional to non-optional
3. In my migration policy add:
let newName = sourceInstance.valueForKey("name") as! StringnewEvent.setValue(newName, forKey: "name")This combination crashes the app (reason=Can't find mapping model for migration)
How can I convert an optional to a String in the migration policy?
(I've done many variations trying to figure this out. Every test I've done starts with deleted the app on my phone, re-downloading the current version from the app store, and then trying to upgrade with new data model. If I just change the 2 string to doubles it works fine, make the changes to make the optional - not optional and I get the error.)