Customize the underlying data model at run time?

I want a model that can be customized by the user. Is this possible with master data or are there better solutions?

Thanks matchi

Ps: this is the app for mac os!

+4
source share
2 answers

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.

+8
source

See NSManagedObjectModel Help Page ...

Models of managed objects are edited until they are used by the schedule of the manager object ... However, as soon as the model should not change ...

I would say that this is definitely an extended section of the "Basic Data" (and Core Data itself is a fairly advanced topic), so as not to be taken lightly. I am not sure that any data already stored in the data warehouse would be useful (or even usable) if you allow the user to change the model.

+1
source

All Articles