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

查看:15
本文介绍了如何创建神奇的 .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.

不过,我认为关于 Core Data 的一些事情我仍然不太明白,很明显.

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?

非常感谢大家!!!

推荐答案

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.

要创建模型包,请选择单个模型,打开主菜单中的 Design 菜单,然后选择 Data ModelAdd Model Version.

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 Add Model Version 可以在 Editor 主菜单中找到.

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

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

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