title: How can I make all Core Data objects inherit from my class rather than NSManagedObject?
body: <p>I created my own class that I want Core Data to use instead of <code>NSManagedObject</code>:</p>
  
  <pre><code>@interface MyManagedObject: NSManagedObject {
    id delegate;
  }
  </code></pre>
  
  <p>I can't use a category since this declares an ivar. All of my Core Data objects use concrete classes rather than being instances of <code>NSManagedObject</code>. I use the code generator to generate these files. Here's an example of what a <code>Contact</code> object might look like:</p>
  
  <pre><code>@interface Contact: NSManagedObject {
  }
  </code></pre>
  
  <p>I know that I can manually change <code>NSManagedObject</code> to <code>MyManagedObject</code> in this generated code, but I will need to do this every time I regenerate the code. Is there any way to make it automatically use my own class?</p>
  
  <p>Additionally, the <code>#import</code> in any solution might be a problem. Ideally I want it to use <code>@class MyManagedObject</code> rather than <code>#import "MyManagedObject.h"</code>, since <code>MyManagedObject.h</code> is located in a library and the header needs a folder prefix to be accessible (e.g. <code>#import "MyLib/MyManagedObject.h"</code>).</p>
  
  <hr>
  
  <p>I tried creating a dummy object in the <code>.xcdatamodel</code> file with the same name and specifying that all objects inherit from it, but there are two problems. The first is that it is using <code>#import "MyManagedObject.h"</code>, which it can't find due to the reason I specified above. The second problem is that I'm not sure it's a good idea to fool Core Data into thinking the class is inheriting from another Core Data object... even if I'm not generating the code file. I'm guessing that Core Data might be doing some unnecessary things behind the scenes because it believes there is an extra class which my classes are inheriting from.</p>
  
  <p>I guess I can solve the first problem using another layer of classes. For example, I would specify that the objects inherit from <code>MyProjectManagedObject</code> and create a <code>MyProjectManagedObject.h</code> file in my project:</p>
  
  <pre><code>#import "MyLib/MyManagedObject.h"
  
  @interface MyProjectManagedObject: MyManagedObject {
  }
  </code></pre>
  
  <p>... and now my auto generated files will look like this:</p>
  
  <pre><code>#import "MyProjectManagedObject.h"
  
  @interface Contact: MyProjectManagedObject {
  }
  </code></pre>
  
  <p>... which will work. The only problem is the second one I mentioned above about extra code running behind the scenes in Core Data. Is this something to worry about or should I ignore it? Are there any other ways to do this which solve both problems mentioned above?</p>