Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 514423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:31:23+00:00 2026-05-13T07:31:23+00:00

So I have a Project with a UITabBarController and a few Navigation Controllers, and

  • 0

So I have a Project with a UITabBarController and a few Navigation Controllers, and I am trying to implement Core Data. Its just not working.

I have a bit of a weird setup:
UITabBarController -> Navigation Controller -> Table View Controller

I have copied all of the Core Data code and added an entity with an attribute (‘Event’ and ‘name’ – just like the tutorials). I keep getting the error:
erminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘+entityForName: could not locate an NSManagedObjectModel for entity name ‘Event”

The error only occurs when I switch to the Table View I want populated by the Core Data content.

I found that the error occurs on this line in the Table View Controller:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];

This seems to correspond with this (in the App Delegate):

NSManagedObjectContext *context = [self managedObjectContext];

if (!context) {

    // Handle the error.

NSLog(@"\nCould not create *context for self");

}

rootViewController.managedObjectContext = context;

Any Help?

Update: I managed to get it working (very exciting moment, and Stanford is winning at the half – so far its a good day). I am now referencing it from the App Delegate. Ahhh, this feels soo good 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:31:24+00:00Added an answer on May 13, 2026 at 7:31 am

    Your managed object context is probably not set and the entity “Event” is obviously not valid for a nil context.

    I use a reference to my app delegate in all my view controllers so they can access the one managed object context. It sounds like others often use a singleton to manage Core Data and would get the managed object context from that.

    UPDATE

    There is a good discussion about where to keep the Core Data stack in Where to place the “Core Data Stack” in a Cocoa/Cocoa Touch application.

    Here is some example code for keeping the Core Data stack in the app delegate:

    Use Apple’s standard Core Data stack implementation in YourAppDelegate. managedObjectContext is implemented as an example, but managedObjectModel and persistentStoreCoordinator must be implemented as well.

    YourAppDelegate.h:

    @interface YourAppDelegate : NSObject <UIApplicationDelegate> {
        // Core Data stuff
        NSManagedObjectModel *managedObjectModel;
        NSManagedObjectContext *managedObjectContext;       
        NSPersistentStoreCoordinator *persistentStoreCoordinator;
    
        // other app ivars
    }
    

    YourAppDelegate.m:

    - (NSManagedObjectContext *) managedObjectContext {
        if (managedObjectContext != nil) {
            return managedObjectContext;
        }
        NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
        if (coordinator != nil) {
            managedObjectContext = [[NSManagedObjectContext alloc] init];
            [managedObjectContext setPersistentStoreCoordinator: coordinator];
        }
        return managedObjectContext;
    }
    

    In every view controller, get a reference to the app delegate and use it to get the managedObjectContext as needed. For example, when setting up the fetchedResultsController;

    RootViewController.h:

    @interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
        NSFetchedResultsController *fetchedResultsController;
    
        YourAppDelegate *app;
    }
    

    RootViewController.m:

    #import "RootViewController.h"
    #import "YourAppDelegate.h"
    
    @implementation RootViewController
    
    @synthesize fetchedResultsController;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        app = (YourAppDelegate*)[UIApplication sharedApplication].delegate;
    }
    
    - (NSFetchedResultsController *)fetchedResultsController {
        if (fetchedResultsController != nil) {
            return fetchedResultsController;
        }
    
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:app.managedObjectContext];
        [fetchRequest setEntity:entity];
    
        // setup the batch size, predicate, & sort keys, etc
    
        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:app.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
        aFetchedResultsController.delegate = self;
        self.fetchedResultsController = aFetchedResultsController;
    
        [aFetchedResultsController release];
        [fetchRequest release];
    
        return fetchedResultsController;
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.