Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread Display Modes
Old Apr 26, 2012, 06:39 AM   #1
macrumors 6502a
Join Date: May 2010
Location: Tokyo, Japan
Error "'+entityForName: could not locate an NSManagedObjectModel"

I save objects to managedObject in AppDelegate, I got error as below when read in my View controller, where did I make wrong

2012-04-26 20:29:47.464 MyApp[1417:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Type''

Now the error is changed to
2012-04-26 22:33:30.304 MyApp[2329:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath not found in entity <NSSQLEntity Type id=6>'

My Entity is like below with a relationship, but I din't set value to it when I save it because I don't have relationship object in Core Data, how can I save such data?

@interface Type : NSManagedObject

@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSSet *types;

@interface Type (CoreDataGeneratedAccessors)

- (void)addTypesObject:(Type *)value;
- (void)removeTypesObject:(Type *)value;
- (void)addTypes:(NSSet *)values;
- (void)removeTypes:(NSSet *)values;

- (void)createType {
    Type *type = (Type *)[NSEntityDescription insertNewObjectForEntityForName:@"Type" inManagedObjectContext:self.managedObjectContext];
    type.type = @"Type1";
    type = (IssueType *)[NSEntityDescription insertNewObjectForEntityForName:@"Type" inManagedObjectContext:self.managedObjectContext];
    type.type = @"Type2";

    // Commit to core data
    NSError *error;
    if (![self.managedObjectContext save:&error]) {
        NSLog(@"Failed to add default user with error: %@", [error domain]);

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
    UINavigationController *navController = (UINavigationController *)[tabController.viewControllers objectAtIndex:0];
    AppViewController *appController = (AppViewController *)navController.topViewController;
    appController.managedObjectContext = self.managedObjectContext;
    // Get a reference to the stardard user defaults
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    // Check if the app has run before by checking a key in user defaults
    if ([prefs boolForKey:@"hasRunBefore"] != YES) {
        // Set flag so we know not to run this next time
        [prefs setBool:YES forKey:@"hasRunBefore"];
        [prefs synchronize];

        [self createType];

    return YES;
//  When the view reappears, read new data for table
- (void)viewWillAppear:(BOOL)animated
    [super viewWillAppear:animated];

    //  Error here
    self.typeList = [CoreDataHelper getObjectsForEntity:@"Type" withSortKey:@"Type" andSortAscending:YES andContext:self.managedObjectContext];
    //  Force table refresh
    [self.typeTableView reloadData];
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2

Last edited by mikezang; Apr 26, 2012 at 08:43 AM.
mikezang is offline   0 Reply With Quote
Old Apr 26, 2012, 06:46 PM   #2
macrumors 68030
MattInOz's Avatar
Join Date: Jan 2006
Location: Sydney
First thing to check when this error gets thrown what is the value of the ManagedObjectContext your asking for the Entity?

You can do this with breakpoint in the right place.

Really you want to check that it's not Nil.
There was a change around iOS5 that a view controller might start asking the context for answers before the AppDelegate has passed the context to this ViewController.

If that is the case then you need to pull the context from the AppDelegate.
There is no such thing as "Collective Wisdom"
[ iPhone 5s, iPad Mini, 13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13"]
MattInOz is offline   0 Reply With Quote
Old Apr 26, 2012, 07:13 PM   #3
Thread Starter
macrumors 6502a
Join Date: May 2010
Location: Tokyo, Japan
Thanks fou your advice, I found where has bug.
mikezang is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Unable To Locate "Install Mac OS X Mountain Lion.app" After Installing It TheBigK OS X 10.8 Mountain Lion 8 Jul 28, 2013 02:26 AM
iPhone: "Prepare Archives" I wasn't able to locate file for the ____ package. This might mean andyACEcandy Jailbreaks and iOS Hacks 1 Feb 4, 2013 01:43 PM
iTunes: how to easily "locate" music on a new hard drive conxobanx Mac Applications and Mac App Store 2 Nov 20, 2012 03:17 PM
How i can fix "Wiki setting error" and "Running time error" ? Amethyst Mac OS X Server, Xserve, and Networking 0 Sep 2, 2012 01:34 PM
Help to locate "browser" like app that can load LOCAL htm files? timidhermit iPad Apps 2 Aug 7, 2012 12:13 PM

Forum Jump

All times are GMT -5. The time now is 11:12 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC