Note that there are some explanatory texts on larger screens.

plurals
  1. PONSManagedObjectContextDidSaveNotification not triggered in iOS 7
    primarykey
    data
    text
    <p>I have a situation where I make some changes to the properties of a NSManagedObject in main thread. It belongs to the main ManagedObjectContext of the app.</p> <p>My app does has threading enabled which downloads data, each thread has it's own ManagedObjectContext created from the most recent state of a single PersistentStore throughout the application.</p> <p>I am implementing <code>NSManagedObjectContextDidSaveNotification</code> so that any changes in the MOC is merged back to the main thread's MOC too. Below is the code for it:</p> <pre><code>- (void)backgroundMOCDidSave:(NSNotification*)notification { // Probable fix for: http://stackoverflow.com/questions/3446983/collection-was-mutated-while-being-enumerated-on-executefetchrequest if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector(backgroundMOCDidSave:) withObject:notification waitUntilDone:YES]; return; } // We merge the background moc changes in the main moc [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification]; } </code></pre> <p>Registering for this notification:</p> <pre><code> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgroundMOCDidSave:) name:NSManagedObjectContextDidSaveNotification object:nil]; </code></pre> <p>Strange things happen in iOS 7 though. I am accessing a NSManagedObject which is created from the main MOC:</p> <ul> <li>When I modify a property of the ManagedObject which belongs to main MOC (main thread) and perform a <code>-save</code> the <code>-backgroundMOCDidSave:</code> call is not triggered</li> <li>When I do not modify any property of the ManagedObject and just perform a <code>-save</code> operation on its MOC the notification is triggered</li> </ul> <p>The same code is working perfectly well in iOS 6. Irrespective of whether any changes is done on the ManagedObject or not, when a <code>-save</code> call is triggered on it's MOC the notification <code>NSManagedObjectContextDidSaveNotification</code> gets triggered.</p> <p>Anyone faced this problem before?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload