Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data: Rename Attribute without having issues with users and their current data

I just want to rename and add attribute on my table for a new version of my app and I want to keep the data if the app was already installed.

Firstly I just set the options:

        let options = [NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption:true]
        try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options)

And I created a new version model, so if I rename the attributes and add another attributes to my table on the new model, do the app gonna keep the data ?

like image 392
Ben Avatar asked Dec 04 '22 23:12

Ben


1 Answers

Per Apple's Core Data Versioning and Migration Guide's section on Lightweight Migrations:

If you rename an entity or property, you can set the renaming identifier in the destination model to the name of the corresponding property or entity in the source model. You set the renaming identifier in the managed object model using the Xcode Data Modeling tool’s property inspector (for either an entity or a property). For example, you can: ... Rename a Car’s color attribute to paintColor

enter image description here

like image 91
Ron Diel Avatar answered May 22 '23 07:05

Ron Diel