2

I'm trying to conform to the MVC paradigm in my iOS app. My model consists of entities stored in coreData which I have set up using the xcdatamodel file.

I want to add some custom methods to these entities in order to keep the Model part separate from the Controller.

In previous versions of Xcode the autogenerated managedObject classes were added automatically to my project and I could add custom methods to these classes. Now I no longer see these auto genterated classes.

I have selected 'Class Definition' for the codegen.

Do I need to create an additional class for each entity to enable custom methods on those entities? Or is there a better way to go about this.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
alionthego
  • 8,508
  • 9
  • 52
  • 125

1 Answers1

1

This is a rather new Xcode feature. Xcode generates the files for you and holds a reference to the generated files. Even the files do not show up in the project, you still can write extensions for the generated classes.

You can find more detailed information in this answer.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • thanks. I'll add the extension as mentioned in that post. as a matter of form and for best practice, where would be the best place to add the extensions for my entities? In a newly created coreDataHelper class or file? – alionthego Jun 13 '17 at 12:26
  • 1
    That is opinion based and imo. depends. Generally I either have a `StoreWorker` for a topic, for instance `FetchOrdersWorker`, where I put in stuff regarding fetching orders. Sometimes I find it clearer to collect code entity wize. In this case I create a file `EntityName+Additions` where all extensions for `EntityName` are in. – shallowThought Jun 13 '17 at 12:30
  • thanks very much. I think the EntityName+Additions will fit my project best. – alionthego Jun 13 '17 at 13:14