核心数据应用程序不保存我的数据,为什么? [英] Core data app does not save my data, why?

查看:219
本文介绍了核心数据应用程序不保存我的数据,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写我的第一个核心数据应用程序。出于某种原因,我的编辑在退出并重新启动应用程序后消失。保存,关闭窗口和重新打开(不退出)保留数据。如果我在textedit中打开保存的文件,我看到我编辑的字段。阅读时必须出错。也许我忘了改变某处的设置?

I am writing my first core data app. For some reason, my edits are gone after quitting and restarting the app. Saving, closing window, and re-opening (without quitting) retains the data. If I open the saved file in textedit, I see my edited field. Something must go wrong during reading. Perhaps I forgot to change a setting somewhere? Does anyone recognize this behavior?

推荐答案

是否在对模型对象进行更改后保存NSManagedObjectContext?

Are you saving the NSManagedObjectContext after making changes to your model objects?

尝试

NSError *error;

if (![myContext save:&error]) {
    // Handle error
}

保存消息返回BOOL以获取成功。您应该检查该值,以查看保存是否成功。如果没有,你传递的NSError引用将包含为什么保存失败的信息。

The save message returns a BOOL for success. You should check that value to see if the save was successful. If not, the NSError reference that you pass in will contain information on why the save may have failed.

如果你发布你的代码,我可以帮助进一步。

If you post your code, I might be able to help further.

这篇关于核心数据应用程序不保存我的数据,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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