title: "Cannot load NSManagedObjectModel. nil is an illegal URL parameter"
body: <p>I want to get the managed object context from AppDelegate, but the app crashed after I put the two lines of code into the method even I did nothing else, and there was a message in debug area:<strong>"CoreData: Cannot load NSManagedObjectModel.  nil is an illegal URL parameter..."</strong></p>
  
  <p>The code added in my method:</p>
  
  <pre><code>AppDelegate *delegate = [UIApplication sharedApplication].delegate;
  NSManagedObjectContext *managedObjectContext = delegate.managedObjectContext;
  </code></pre>
  
  <p>-managedObjectModel method in AppDelegate:</p>
  
  <pre><code>- (NSManagedObjectModel *)managedObjectModel {
  // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
  if (_managedObjectModel != nil) {
      return _managedObjectModel;
  }
  NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"FoodPin" withExtension:@"momd"];
  _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
  return _managedObjectModel;
  }
  </code></pre>
  
  <p>and  the -managedObjectContext method:</p>
  
  <pre><code>- (NSManagedObjectContext *)managedObjectContext {
  // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
  if (_managedObjectContext != nil) {
      return _managedObjectContext;
  }
  
  NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
  if (!coordinator) {
      return nil;
  }
  _managedObjectContext = [[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType];
  [_managedObjectContext setPersistentStoreCoordinator:coordinator];
  return _managedObjectContext;
  }
  </code></pre>
  
  <p><strong>"FoodPin" is my project name</strong>.So what's wrong here?I'm new to iPhone programming (Core Data in particular).</p>
  
  <p>Can anyone help me?</p>
  
  <p>Thanks...</p>