Search code examples
objective-ccore-dataxcode5

Renaming a core data property within an NSManagedObject class


I want to rename a property, sortOrder:

enter image description here

to sequence, within an NSManagedObject class. (example illustration only)

enter image description here

And have followed the steps of Lightweight Migration.

enter image description here

The challenge is that the Lightweight Migration doesn't actually affect the NSManagedObject class (FormItems).

So the code still uses the sortOrder property. I can run a refactor-rename through XCode to change the code, but will that then break my backwards DB compatibility due to the renaming within the class?

What am I misunderstanding here?


Solution

  • Lightweight migration should work as expected. This statement

    The challenge is that the Lightweight Migration doesn't actually affect the NSManagedObject class (FormItems).

    is not necessarily true. It LW migration should affect all changed entities.

    You can refactor your code to use the new name and

    1. Create a new model version.
    2. Make the changes to the property after changing to the new model version.
    3. Make sure the persistent store has the right options.
      NSMigratePersistentStoresAutomaticallyOption and
      NSInferMappingModelAutomaticallyOption