NSManagedObjectContextObjectsDidChangeNotification not always called instantly
Asked Answered
B

1

6

I have an Mac Application using a NSPersistentDocument. I want to get notified when Objects are deleted to save this information using Core Data. So I'm listening for NSManagedObjectContextObjectsDidChangeNotification. Often it is called instantly when objects are deleted, but sometimes it is only called after the persistent document is saved with all deleted objects not being notified before. Because I want to let the user directly export all existing objects (and not the deleted anymore) what to I have to do to become notified instantly to save the delete information or do I have to use it in another way?

Bathometer answered 12/10, 2011 at 15:13 Comment(0)
W
9

NSManagedObjectContextObjectsDidChangeNotification is no longer issued as frequently or quickly on 10.7 as on 10.6. You can force Core Data to issue the notification (assuming there are changes) by calling -[NSManagedObjectContext processPendingChanges].

Whenever answered 13/10, 2011 at 12:3 Comment(3)
thanks so far. I want to use this when data is deleted from a TableView that has a ArrayController as its source. Can I interrupt in another part to store information I need or to call processPendingChanges?Bathometer
You can observe the arrangedObjects on the NSArrayController, and perform processPendingChanges there.Whenever
thanks, observing arrangedObjects and calling processPendingChanges sends the notification instantly. That's what I needed.Bathometer

© 2022 - 2024 — McMap. All rights reserved.