在现有coredata模型中添加新属性 [英] Adding new attributes in existing coredata model

查看:526
本文介绍了在现有coredata模型中添加新属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是coredata的新手,从来没有使用过,现在,我正在开发一个项目,其中一些工作已经由前开发人员完成。 Coredata用于保存项目中的数据,现在我需要在现有的coredata模型中添加一些新的属性,但是当我添加了属性(我在.h文件中添加了@property,在.m中添加了@dynamic), setAttribute工作正常(虽然idk如果它是否被书写),但是当我尝试读取的属性应用程序崩溃。我不太了解coredata,我尝试了一些博客,他们建议使用.xcdatamodel但在我的情况下,当我试图打开这个文件Xcode崩溃。现在我非常困在这里。请在这方面帮助我,现在我只需要一个针点解决方案,只是通过这种情况。感谢您的考虑。

I am a newbie to coredata never worked with it, right now, I am working on a project on which some work has already been done by the previous developer. Coredata is being used in saving data in the project, Now I need to add some new attributes in the existing coredata models but when I added the attribute (I added @property in the .h file and @dynamic in the .m), the setAttribute is working fine (though idk if it's getting written or not) but when I try to read the attribute the application gets crashed. I don't know much about the coredata, I tried a few blogs they're suggesting to use .xcdatamodel but in my case when I try to open this file the Xcode gets crashed. Now I am very much stuck in here. Kindly help me in this regard, right now I just need a pin point solution to just get through this situation. Thanks in advance for your consideration.

推荐答案

是的,你需要先把你的旧数据库文件。每当您进行任何模型更改时执行此操作。在模拟器上,选择iOS模拟器 - >重置内容和设置。

Yep, you need to blow away your old database file first. Do this whenever you make any model changes. On the simulator, select iOS Simulator -> Reset Content and Settings.

如果它在您的设备上,请完全删除应用程序。

If it's on your device, delete the app completely.

然后,再试一次。这次将根据您的新模型重新创建备份持久存储。你会很好的。

Then, try again. This time the backing persistent store will be recreated according to your new model. You'll be good to go.

这篇关于在现有coredata模型中添加新属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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