0
  • I started creating entities in the xcdatamodeld (xcdatamodel) file.
  • I subclassed entities using the Create NSManagedObject Subclass… menu entry.
  • I added custom code to these subclasses.

If i want to make changes (like add/remove an attribute, a relationship) to an entity at this moment, where would i make these changes:

  • at the xcdatamodeld (xcdatamodel) file,
  • at my custom NSManagedObject subclass,
  • at both, the xcdatamodeld (xcdatamodel) file and my custom NSManagedObject subclass?

So, what is the relationship between NSManagedObject subclasses and the xcdatamodeld file?
Do i have to keep those two elements in sync?

MartinW
  • 4,966
  • 2
  • 24
  • 60

1 Answers1

1

xcdatamodeld rules :) or more specifically, the resulting managed model. Whatever is there or not will determine the store structure.

So ...
You make your changes in the model file first and foremost.
This will enable you to echo these changes to the managed object subclasses.
This is not mandatory for addition, but I believe it is mandatory for attribute/relationship removal (not tested).

If you have custom code, I will advise you to add it in a category over the managed object subclass as this will allow you to easily regenerate your classes interface when you change your model file.

Dan Shelly
  • 5,991
  • 2
  • 22
  • 26
  • Thank you. I like the idea with the category! Still i have not fully understood how the managed model and the NSManagedObject subclasses are related… – MartinW May 31 '14 at 12:41
  • The model is creating a specialized object (a managed object) to deal with the specification described in the model. this object is optimized by CoreData. when you subclass a managed object, you must do it in a way thay will not contradict the model, and allow the model to implement the core components itself. in general the model is a blueprint of the managed object subclass. – Dan Shelly May 31 '14 at 13:25