Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 744049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:56:00+00:00 2026-05-14T08:56:00+00:00

I have an iphone app that uses Core Data to do storage. I have

  • 0

I have an iphone app that uses Core Data to do storage. I have successfully deployed it, and now I’m working on the second version. I’ve run into a problem with the data model that will require a few very simple data transformations at the time that the persistent store gets upgraded, so I can’t just use the default inferred mapping model.

My object model is stored in an .xcdatamodeld bundle, with versions 1.0 and 1.1 next to each other. Version 1.1 is set as the active version. Everything works fine when I use the default migration behavior and set NSInferMappingModelAutomaticallyOption to YES. My sqlite storage gets upgraded from the 1.0 version of the model, and everything is good except for, of course, the few transformations I need done.

As an additional experimental step, I added a new Mapping Model to the core data model bundle, and have made no changes to what xcode generated. When I run my app (with an older version of the data store), I get the following

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'

What am I doing wrong? Here’s my code for to get the managed object model and the persistent store coordinator.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"gti_store.sqlite"]];

    NSError *error;
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
                                                   configuration:nil 
                                                             URL:storeUrl 
                                                         options:options 
                                                           error:&error]) {
        NSLog(@"Eror creating persistent store coodinator - %@", [error localizedDescription]);
    }    

    return _persistentStoreCoordinator;
}


- (NSManagedObjectModel *)managedObjectModel {

    if(_managedObjectModel == nil) {

        _managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];    
        NSDictionary *entities = [_managedObjectModel entitiesByName];

        //add a sort descriptor to the 'Foo' fetched property so that it can have an ordering - you can't add these from the graphical core data modeler
        NSEntityDescription *entity = [entities objectForKey:@"Foo"];   
        NSFetchedPropertyDescription *fetchedProp = [[entity propertiesByName] objectForKey:@"orderedBar"];
        NSSortDescriptor* sortDescriptor =  [[[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES] autorelease];
        NSArray* sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
        [[fetchedProp fetchRequest] setSortDescriptors:sortDescriptors];
    }
    return _managedObjectModel;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:56:01+00:00Added an answer on May 14, 2026 at 8:56 am

    I haven’t thought this out very carefully, it’s just an observation as I was having the same problem, and I too have found very few references to this error on the web.

    In my case the problem was that I had setup one of my application’s objects to observe

    NSManagedObjectContextObjectsDidChangeNotification like so

            [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(observeContextSave:)
                                                     name:NSManagedObjectContextDidSaveNotification
                                                   object:nil];
    
    
    - (void) observeContextSave:(NSNotification*) notification {
    [[self managedObjectContext] mergeChangesFromContextDidSaveNotification:notification];}
    

    Once I moved this code so that is was executed after the migration, the error went away.

    Anyway. I’m sure your circumstances are different. But it may help to think about what observations you have setup on notifications from your managedObjectContext.

    Update: Having thought about this a bit more, I guess it happens because multiple persistent stores are created during migration, which means that NSManagedObjectContextDidSaveNotification will be sent from a context with a different persistent store to the context that is sent mergeChangesFromContextDidSaveNotification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 428k
  • Answers 428k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer All Tests in the Current Context: The current context depends… May 15, 2026 at 1:08 pm
  • Editorial Team
    Editorial Team added an answer The most used solution with Java is URLRewrite Filter .… May 15, 2026 at 1:08 pm
  • Editorial Team
    Editorial Team added an answer You mean JSONObject flash = json.getJSONObject(0); JSONObject Flash = flash.getJSONObject("Flash");… May 15, 2026 at 1:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.