i need able create new core data entities during runtime. i've written code create objects programmatically, however, can't add entities during runtime model immutable.
my problem similar post, there no satisfactory answer: how dyanmic create new entity (table) via coredata model?
the documentation regarding changing core data model explains:
managed object models editable until used object graph manager (a managed object context or persistent store coordinator). allows create or modify them dynamically. however, once model being used, must not changed. enforced @ runtime—when object manager first fetches data using model, whole of model becomes uneditable. attempt mutate model or of sub-objects after point causes exception thrown. if need modify model in use, create copy, modify copy, , discard objects old model.
however, i'm unclear on saying--that whole core data model can't changed once persistent store coordinator has been used or attributes/etc of individual entities can't changed.
to clear, not want change attributes of current entities, want add new entities. seems weird me have use migration add new entities.
any thoughts?
thanks!
the documentation pretty clear.
- copy model.
- apply changes new copy.
- destroy old moc, persistent store coordinator, , objects created those.
- apply migration, if necessary.
- create new core data stack (moc, psc, etc) using updated model.
the migration sticking point, should do-able.