NSManagedObjectContextObjectsDidChangeNotification 并不总是立即调用
我有一个使用 NSPersistentDocument 的 Mac 应用程序。我希望在删除对象时收到通知,以使用核心数据保存此信息。所以我正在监听 NSManagedObjectContextObjectsDidChangeNotification。通常它会在对象被删除时立即调用,但有时仅在保存持久文档后调用,并且之前不会通知所有已删除的对象。因为我想让用户直接导出所有现有对象(而不是已删除的对象),我必须做什么才能立即收到通知以保存删除信息,还是必须以其他方式使用它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSManagedObjectContextObjectsDidChangeNotification 在 10.7 上不再像 10.6 上那样频繁或快速地发出。您可以通过调用
-[NSManagedObjectContext processPendingChanges]
强制 Core Data 发出通知(假设有更改)。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]
.