I'm new to the Apple dev environment, but have decades of dev experience. Steep learning curve! I am wiring though the Locations example, but have run into t road block. The Locations example has not been updated (AFAIK) for iOS 5, but I seem to be negotiating the differences OK. I keep getting this error:
uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Event''
I have found several instances of this question and have checked the things suggested. The most detailed was from a suggestion to check context.persistentStoreCoordinator.managedObjectModel.entities to see if the MOC has been created. I get a count of one from this collection and I have one entity defined, Event. So it would seem I have instantiated the MOC.
The main code I have written is in the AppDelegate. It is listed below. These three functions appear to run correctly. As soon as I exit from didFinishLaunchingWithOptions, the app crashes with the exception. The URL created for the MOM is //localhost/Users/bob/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/9189FD66-7C27-4B2E-9FA6-199361342EDC/Locations.app/Locations.momd/
I have scattered a few breakpoints around my rootViewController and those are not getting hit, so I am not sure where the code is going after didFinishLaunching... exits. The MOM looks correct and the name is not misspelled AFAIK.
May main question is what am I doing wrong?
Second, I follow that URL and I find no Library under /Users/bob. Are there hidden directories? Is this the problem?
Third, when I exit didFinishLaunching... I am in assembly code. Is there any easy way to get the debugger to stop on the next source code it enters, or do I have to plant breakpoints in the right place?
Thanks in advance,
-Bob
uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Event''
I have found several instances of this question and have checked the things suggested. The most detailed was from a suggestion to check context.persistentStoreCoordinator.managedObjectModel.entities to see if the MOC has been created. I get a count of one from this collection and I have one entity defined, Event. So it would seem I have instantiated the MOC.
The main code I have written is in the AppDelegate. It is listed below. These three functions appear to run correctly. As soon as I exit from didFinishLaunchingWithOptions, the app crashes with the exception. The URL created for the MOM is //localhost/Users/bob/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/9189FD66-7C27-4B2E-9FA6-199361342EDC/Locations.app/Locations.momd/
I have scattered a few breakpoints around my rootViewController and those are not getting hit, so I am not sure where the code is going after didFinishLaunching... exits. The MOM looks correct and the name is not misspelled AFAIK.
May main question is what am I doing wrong?
Second, I follow that URL and I find no Library under /Users/bob. Are there hidden directories? Is this the problem?
Third, when I exit didFinishLaunching... I am in assembly code. Is there any easy way to get the debugger to stop on the next source code it enters, or do I have to plant breakpoints in the right place?
Thanks in advance,
-Bob
Code:
#import "AppDelegate.h"
#import "MasterViewController.h"
#import "RootViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
//Handle error
}
//Pass managed object context to view controller
rootViewController.managedObjectContext = context;
id x = context.persistentStoreCoordinator.managedObjectModel.entities;
int y = [x count];
UINavigationController *aNavigationController = [[UINavigationController alloc]
initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
- (NSManagedObjectContext *)managedObjectContext
{
if (__managedObjectContext != nil)
{
return __managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil)
{
__managedObjectContext = [[NSManagedObjectContext alloc] init];
[__managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return __managedObjectContext;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Locations.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
//if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
// configuration:nil URL:storeURL options:nil error:&error])
//{
/*
Replace this implementation with code to handle the error appropriately.
*/
//}
return __persistentStoreCoordinator;
}
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Locations" withExtension:@"momd"];
NSLog(@"scheme: %@\n", [modelURL scheme]);
NSLog(@"resource: %@\n", [modelURL resourceSpecifier]);
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}