在崩溃之前保存核心数据上下文 [英] Saving Core Data Context before Crashing

查看:92
本文介绍了在崩溃之前保存核心数据上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我们在XCode中点击停止,它将关闭应用程序,模仿崩溃行为。



但如果我的核心数据上下文


  1. 有没有任何解决方法?



$ b $ b

感谢。

解决方案

根据我的经验,你应该决定使用Core Data保存机制时的正确粒度。



IMHO(也许其他人可能有不同的意见)没有标准可以遵循。我的经验法则考虑两个不同的方面。 用户效果



在第一种情况下,每当用户执行关键操作时,都应保存。例如用户已经在表单中插入了很多值,因此他不希望再次插入它们。关于第二方面,保存操作可能会影响应用程序的性能。如果你经常写更改到磁盘,应用程序的响应速度会降低。相反,在内存中有这么多对象可能会导致内存警告(这将导致Core Data采取特定的行为)。



一个权衡可以使用后台操作来保存更改或利用新的Core Data API。显然,以前的规则仍然有效。


For example if we hit "Stop" in XCode, it will close the app, mimicking the crash behaviour.

But if my Core Data Context hasn't been saved, when I go back, the data won't be there.

  1. Are there any workaround for this?

  2. Should I save the context every time a big operation is finished?

Thanks.

解决方案

Based on my experience you should decide the right granularity when you use Core Data save mechanism.

IMHO (maybe someone else could have different opinions) there is no standard to follow. My rule of thumb is taking into considerations two different aspects. The user and performances.

In the first case, you should save whenever the user performs critical operations. e.g. the user has inserted a lot of values in a form and hence he will expect to not insert them again. Regarding the second aspect, save operations could impact the performance of your app. If you frequently write changes to disk the app will be less responsive. On the contrary having so many objects in memory could led to memory warning (those will cause Core Data to take specific behaviors).

A tradeoff could be using background operations to save changes or take advantage of new Core Data API. Obviously, previous rules still remain valid.

这篇关于在崩溃之前保存核心数据上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆