title: iOS - CoreData - TableViewController - NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext
body: <p>I created a storyboard with a <code>UITableViewController</code>, then added a Core Data entity. The application at this point built and run without errors, but the <code>UITableViewController</code> was showing no data.</p>
  
  <p>I deleted the TVC and rebuilt in StoryBoard, but ever since I'm getting an error when I run the application and try to open the TVC:</p>
  
  <blockquote>
    <p><em>*</em> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a
    legal NSManagedObjectContext parameter searching for entity name
    'Attractions''</p>
  </blockquote>
  
  <p>With a bit of research,  realize that this is due to my <code>managedObjectContext</code> being empty, but for the life of me I cannot figure out WHY it's empty.</p>
  
  <p>In the TVC header file:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "Attractions.h"
  #import "AttractionListViewCell.h"
  #import "ApplicationNameAppDelegate.h"
  
  @interface AttractionListViewController : UITableViewController
  {
      NSManagedObjectContext *managedObjectContext;
      NSMutableArray *AttractionsArray;    
  }
  
  @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
  @property (nonatomic, retain) NSMutableArray *AttractionsArray;
  
  - (void) fetchrecords;
  
  @end
  </code></pre>
  
  <p>In the TVC model file:</p>
  
  <pre><code>ApplicationNameAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  NSManagedObjectContext *managedObjectContext = [appDelegate managedObjectContext];
  
  NSLog(managedObjectContext);
  // Create connection to the DB via Context
  NSEntityDescription *entity = [NSEntityDescription entityForName:@"Attractions" inManagedObjectContext:managedObjectContext];    
  </code></pre>
  
  <p>In the <em>ApplicationNameAppDelegate.h</em> file:</p>
  
  <pre><code>@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  
  - (void)saveContext;
  - (NSURL *)applicationDocumentsDirectory;
  </code></pre>
  
  <p>Any help or insight you could provide would be much appreciated.</p>
  
  <p>EDIT - Added AppDelegate info:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "AttractionListViewController.h"
  #import &lt;CoreData/CoreData.h&gt;
  
  @class AttractionListViewController;
  
  @interface AppNameAppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  {
      NSManagedObjectModel *managedObjectModel;
      NSManagedObjectContext *managedObjectContext;
      NSPersistentStoreCoordinator *persistentStoreCoordinator;
  }
  
  @property (strong, nonatomic) AttractionListViewController *viewController;
  @property (strong, nonatomic) UIWindow *window;
  
  @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  
  - (void)saveContext;
  - (NSURL *)applicationDocumentsDirectory;
  
  @end
  </code></pre>