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 8499889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:47:23+00:00 2026-06-11T00:47:23+00:00

I am really baffled today by what I discovered. I thought as long as

  • 0

I am really baffled today by what I discovered.

I thought as long as all context are using the same Core Data persistent store, any changes in one context should appear in the other context after saving the context.

E.g. In view controller A I have 1 context (context A), in view controller B, I have another context (context B). Now both context A and context B point to the same persistent store.

In context A, I fetched a managed object from the persistent store, updated a property of the managed object, then I save the changes back to the persistent store with managedObjectContext save operation.

Now I open my second view controller and perform a fetch request from the same persistent store but my second view controller does not see the updated property change, until I restart the simulator.

The really strange thing is, if it’s the first time I insert a new managed object into the persistent store, controller B will see the changes but subsequent changes are not shown.

I have already fixed this problem after a long battle, I just want to know why having two separate context (both on main thread of course) sharing the same persistent store does not see the changes until simulator restart.

For those who want to know how I fixed it, in my base view controller which controller A and B both inherit from, instead of alloc-initing a new context (a hence why controller A and B have two separate contexts), I told the base view controller to reference the context in the app delegate (as a result, controller A and B now point to the same context).

Here’s a diagram explaining what I am seeing:

enter image description here

The resulting value fetched in second view controller is the old value.

If I commit some data to the persistent store, it should become permanent and accessible ANYWHERE as long as I am fetching from that same persistent store, unless I am misunderstanding that managedObjectContext save: doesn’t actually make the changes to persistent store immediately until the app results.

  • 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-06-11T00:47:25+00:00Added an answer on June 11, 2026 at 12:47 am

    Zhang,

    without details it’s difficult to figure out the problem.

    A simple suggestion is to verify if you merge changes between the two different context within your app. In other words, you need to verify the main context merges changes that come from the other one. This could simple achieved like the following.

    Register for this notification where, for example, in your AppDelegate or you are creating the Core Data stack.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextChanged:) name:NSManagedObjectContextDidSaveNotification object:nil];
    

    Implement the contextChanged: method to merge changes.

    - (void)contextChanged:(NSNotification*)notification
    {
        if ([notification object] == [self managedObjectContext])
            return;
    
        if (![NSThread isMainThread]) {
            [self performSelectorOnMainThread:@selector(contextChanged:) withObject:notification waitUntilDone:YES];
            return;
        }
    
        [[self managedObjectContext] mergeChangesFromContextDidSaveNotification:notification];
    }
    

    For further info see Marcus Zarra tutorial.

    In addition, if you use tables in combination with NSFetchedResultsController remember to implement delegate’s methods. For info see NSFetchedResultsControllerDelegate class.

    Hope that helps.

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

Sidebar

Related Questions

I'm having an issue with the RadEditor for MOSS, I'm really baffled as to
Really confused why the QR output using RcppArmadillo is different than QR output from
I've been working on this file for awhile and I'm just really baffled. I
I'm reading Javascript: The Good Parts and am totally baffled by what's really going
I'm really baffled by this. Have I managed to do something to cause this,
I've been really really baffled by this for hours now, so I figured it's
I'm baffled by the results I'm getting from FFT and would appreciate any help.
Today I thought it would be a nice idea to overload operator<< for C
Really baffled here. I'm just trying to do an addClass('test') on a hovered target...
I'm really baffled with the following. When the gallery is created in FF/Chrome etc,

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.