Tuesday, March 27, 2012

How to fix: CoreData error "NSInternalInconsistencyException" - iPhone App Development


Migrating this blog post from my old blog. This might help if some one gets stuck with this "NSInternalInconsistencyException".

If you see the following exception while working with core data (iphone sdk):


[Session started at 2010-06-01 22:47:09 -0700.]
2010-06-01 22:47:11.150 MyCoreDataList[88744:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Stock''
2010-06-01 22:47:11.153 MyCoreDataList[88744:20b] Stack: (
    9905243,
    2444394043,
    7893163,
...

This happens because, u r trying to load a DB row from an object context that hasn't been loaded yet. So ur option: u can set-up right ther or just before loading this view...


Solution
Place the following segment in your RootViewController's ViewDidLoad() method


if(managedObjectContext == nil){
managedObjectContext = [(MyCoreDataListAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

No comments:

Post a Comment