如何创建魔术的.xcdatamodeld文件夹/包? [英] How to create the magic .xcdatamodeld folder / package?

查看:256
本文介绍了如何创建魔术的.xcdatamodeld文件夹/包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我管理(偶然,不要问)删除我的Core Data数据模型文件和类。而且我完全无法再创建文件,与在新开始的项目中完全相同,这些文件是由XCode自动准备的。

Recently, I managed (by accident, don't ask) to delete my Core Data datamodel files and classes. And I was completely and utterly unable to create the files again to be exactly the same as they would be in a freshly started project where those files are being prepared automatically by XCode.

在新项目中,文件将如下所示:

In a new project, the files would look like this:

,而我可以创建的是:

我提到应用程式无法运作办法?它崩溃说模型不能 nil 。通过启动一个相同名称的新项目并将文件拖到旧的项目 - 而不是最优雅的解决方案,我想这个问题解决了。

Did I mention that the app didn't work anymore this way? It crashed saying the model must not be nil. The problem was solved by starting a new project with the same name and dragging the files over to the old one - not the most elegant solution, I suppose.

有关核心数据的事情,我仍然不太明白,明显。

I figured however that there are things about Core Data that I still don't quite understand, obviously.

请,启发我 - .xcdatamodeld文件夹背后有什么神奇?为什么Foo.xcdatamodel具有绿色的勾选图标?数据模型是否需要以某种方式编译或处理?

Please, enlighten me - what's the magic behind the .xcdatamodeld folder? Why would Foo.xcdatamodel feature that green checked-icon? Does the datamodel need to be compiled or processed in some way?

感谢alot guys !!!

Thanks alot guys!!!

推荐答案

coredata模型包保留所有模型版本。
带有绿色复选标记的模型是当前版本,存储在coredata中的数据将使用此方案保存。
所有其他数据模型版本都支持数据库迁移,如果数据模型中只有小的更改,则可以自动升级存储在不同版本中的数据。

the coredata model bundle keeps all your model versions. The model with the green checkmark is the current version, data stored into coredata will be saved using this scheme. All other datamodel versions are there to support database migration, data stored in a different version can be upgraded automatically if there are only small changes in the data model.

要创建一个模型包,选择单个模型,打开主菜单中的设计菜单,选择数据模型 添加模型版本

To create a model bundle you select the single model, open the Design menu in the mainmenu and select Data Model and Add Model Version.

您的应用程序崩溃,因为它需要一个类型为 momd 。

Your app is crashing because it expects a datamodel bundle with the type momd.

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"foobar" ofType:@"momd"];

如果你只有一个Datamodel,它不会被编译成momd文件。但我忘了实际的扩展。

If you have only one Datamodel it is not compiled into a "momd"-file. But I forgot the actual extension.

在Xcode4 添加模型版本 code>编辑器主菜单。

In Xcode4 Add Model Version can be found within the Editor main menu.

这篇关于如何创建魔术的.xcdatamodeld文件夹/包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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