Search code examples
iosobjective-ccore-datacore-data-migration

Updating Core-Data Model Entity and the backed NSManagedobject subclass


Let's say I have a model entity with 3 attributes.
I then generate the NSManagedobject subclass for this entity and add custom methods along with properties to this class.
At a later day I added a couple of new attribute to this entity.

Objective
I want the backed NSManagedobject subclass to reflect these new attribute.

Problem
The only solution I see is going to {Editor->Create NSManagedobject Subclass} in Xcode, but this way overrides the class.

Question
Is there a way to update an Entity and the backed NSManagedobject subclass without overriding the class.


Solution

  • Editing the managed object subclass by hand is fine. Let's say you added a new string attribute to the entity. You would add a property to your managed object subclass:

    @property (nonatomic, copy) NSString *myAttribute;
    

    And mark it as dynamic:

    @dynamic myAttribute;
    

    Done! Having Xcode generate the class is intended to provide a starting point. It's not doing anything super special to tie your property to an entity attribute.