This is explained in the "Creating a Managed Object Model" Apple Core Data Utility . In general, as soon as you reference a managed object model, you can use NSEntityDescription and NSAttributeDescription to configure entities and their attributes in a managed object model.
Please note, however, that in most cases, after changing the managed object model, it will no longer be compatible with existing persistent data warehouses, which means that you will have to transfer data from the old persistent storage to the new one. This is certainly not an attempt at easy adoption.
Of course, as mentioned in the comments, Core Data can also automatically transfer data, a process known as lightweight migration . In general, to do this
The master data must be able to find the source object and the destination object models itself at runtime. (The main data is looking for the bundles returned by NSBundle s allBundles and allFrameworks .) Then, analyze the schema changes for the permanent objects and properties and generate a model for the intended mapping. In order for Core Data to do this, the changes must correspond to the obvious migration, for example:
- Easy add new attribute
- Optional attribute becomes optional
- Optional attribute becomes optional and defines a default value.
Does this match your use case or do you want to allow your users to modify the model of managed objects in such a way as to facilitate migration?
In any case, I highly recommend that you read the following documents before attempting to allow users to modify Core Data models.
source share