我们如何防止“CoreData 无法完成故障”?
我们偶尔会收到“CoreData 无法完成故障”的信息。我们已阅读 Apple 文档,但不清楚允许保留哪些内容。我们非常小心地为每个线程创建一个上下文等。但是,我们的应用程序正在做的一件事是我们在 UIViewController 上保留 NSManagedObjects(通常通过 NSArray 或 NSDictionary)。我猜发生的事情是对象关系正在发生变化,而我们没有处理适当的通知。
有人对核心数据更好的设计有什么建议吗?当我们收到错误时,我看不到我们实际上从上下文中删除了任何内容来导致错误。如果 UIViewController 保留状态,是否有必要处理 NSManagedObjectContextObjectsDidChangeNotification?任何建议将不胜感激。
We get "CoreData could not fulfill a fault" every once in a while. We have read through the Apple documentation but are unclear on what is allowed to be retained. We have been very careful about creating one context per thread, etc. However, one thing our app is doing is we are retaining NSManagedObjects on our UIViewControllers (usually via a NSArray or NSDictionary). I'm guessing what's going on is the object relationships are changing and we are not handling the appropriate notification.
Does anyone have any suggestions on the better design with regards to Core Data? When we get the error, I cannot see that we actually deleted anything from the context to cause the fault. Is it necessary to handle NSManagedObjectContextObjectsDidChangeNotification on our UIViewControllers if they are retaining state? Any suggestions would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 Core Data 中注册变更通知。这将允许您在托管对象发生变化时更新它们。有关更多信息,请参阅核心数据文档。您将对注册和响应更改的 2 个方法感兴趣:
mergeChanges 选择器(您的方法)将调用以下方法来同步其他线程的任何更改。它看起来像这样:
You can register for change notifications in Core Data. This will allow you to update your managed objects when they change. See the Core Data Docs for more info. You're going to be interested in 2 methods to register and respond to changes:
The mergeChanges selector (your method) will call the following method to synchronize any changes from other threads. It will look something like this: