iPhone Core Data Example produces exception

一个人想着一个人 提交于 2020-01-01 05:47:11

问题


No longer under NDA.

There was an ommision in the iPhone Core Data example, but is now corrected. Also the sample code was always correct, they just left out some details in the tutorial.

(Please refer to iPhone Dev Forums for explanation)

I built an app twice and received the same error twice (but in 2 different places):

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Event''

I read the apple docs:

It speaks to a problem with the model missing, or the context is nil, or the persistence store is not valid.

However as this is my first Core Data project, I'm a little weak in debugging. I can post code if needed.

Any help is much appreciated.


回答1:


I found the answer. (If you would like a iPhone 3.0 sdk version of this answer, refer to the link at the bottom of the page) This what should be in the app delegate applicationDidFinishLaunching method should be like so:

(void)applicationDidFinishLaunching:(UIApplication *)application { 

    NSManagedObjectContext *context = [self managedObjectContext];
    if (!context) {
        // Handle the error.
    }

    RootViewController *rootViewController = [[RootViewController alloc] 
                                              initWithStyle:UITableViewStylePlain]; 

    rootViewController.managedObjectContext = context;

    UINavigationController *aNavigationController = [[UINavigationController 
                                                      alloc] initWithRootViewController:rootViewController]; 
    self.navigationController = aNavigationController; 
    [window addSubview:[navigationController view]]; 
    [window makeKeyAndVisible]; 
    [rootViewController release]; 
    [aNavigationController release]; 
} 

iPhone Dev Forums Link



来源:https://stackoverflow.com/questions/657042/iphone-core-data-example-produces-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!