title: Core Data - initWithEntity causes unrecognized selector sent to instance
body: <p>I want to use core data to persist some entities like events.</p>
  
  <p>Therefore I use the classes <code>DSManagedObject</code> and <code>Event</code></p>
  
  <p>The class <code>DSManagedObject</code> extends <code>NSManagedObject</code> and has general methods that all entities can use.
  The class <code>Event</code> extends <code>DSManagedObject</code>.</p>
  
  <p>The following code is the <code>DSManagedObject.h</code> and <code>.m</code>. The relevant code in the <code>.m</code> is just the <code>getContext</code>-method.</p>
  
  <pre><code>@interface DSManagedObject : NSManagedObject
  
  + (NSManagedObjectContext *)getContext;
  - (NSArray*)getEntitiesForName:(NSString*)_entityName context:(NSManagedObjectContext*)_context;
  - (Event*)getEntityForName:(NSString*)_entityName forEventId:(NSInteger)_eventId context:(NSManagedObjectContext*)_context;
  - (bool)deleteEntityForName:(NSString*)_entityName forEventId:(NSInteger)_eventId context:(NSManagedObjectContext*)_context;
  
  @end
  
  
  @implementation DSManagedObject
  
  + (NSManagedObjectContext *)getContext {
  
      NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,
                               [NSNumber numberWithBool:YES],
                               NSInferMappingModelAutomaticallyOption, nil];
  
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *basePath = ([paths count] &gt; 0) ? [paths objectAtIndex:0] : nil;
      NSURL *storeUrl = [NSURL fileURLWithPath:[basePath stringByAppendingFormat:@"DesertStorm.sqlite"]];
      NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:nil]];
      NSError *error = nil;
  
      if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {
          NSLog(@"error loading persistent store..");
          [[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:nil];
          if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {
              NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
              abort();
          }
      }
  
  
  
      NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];
      [context setPersistentStoreCoordinator:persistentStoreCoordinator];
  
      return context;
  
  
  }
  </code></pre>
  
  <p>Now in the class <code>Event</code> I want to call <code>initWithEntity</code> but then the error <code>[Event managedObjectModel] unrecognized selector sent to instance</code> occurs.
  What's the reason ? :(</p>
  
  <pre><code>@interface Event : DSManagedObject
  
  @property (assign)              NSInteger   eventId;
  
  @end
  
  
  @implementation Event
  
  @dynamic eventId;
  
  - (id)init {
  
      NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:[DSManagedObject getContext]];
      self = [self initWithEntity:entity insertIntoManagedObjectContext:[DSManagedObject getContext]];  // error occurs
      self = [super init];
      if (self) {
  
      }
      return self;
  }
  
  ...
  
  @end
  </code></pre>
  
  <p>I'm new in using core data so show understanding ;)
  Thanks for help</p>
  
  <p>PS: If you wonder why I override the <code>init</code>-method...complex reason^^</p>