Search code examples
ioscore-datansmanagedobjectcontext

managedObjectContext giving an error


For some reason I'm getting an error at the managedObjectContext = section in line 9. Here's the code I have

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Setup Patterned Background
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Textured Background.png"]];

    if (managedObjectContext == nil)
    {
        managedObjectContext = [(ZAPAppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext];
    }
    self.napkinsArray = [ZAPNapkinDrafts getNapkinDrafts:self.managedObjectContext];
}

Here's what the error states is the reason:

reason=The model used to open the store is incompatible with the one used to create the store

Any help would be appreciated!


Solution

  • It would seem that you have made changes to your data model, and are trying to load old data from the persistent store. You can delete your app from the device/simulator and try to reload it. That should fix the problem.

    You should look up Core Data persistent store migration since you won't be able to delete all your data in a production app.

    Here is a quick overview of Core Data migration:

    http://i.ndigo.com.br/2012/04/ios-core-data-migration/