找不到momd文件:Core Data问题 [英] Can't find momd file: Core Data problems

查看:515
本文介绍了找不到momd文件:Core Data问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Aw geez!我扭动了一些东西!

Aw geez! I screwed something up!

我是一个Core Data noob,在我的第一个iOS应用程序上工作。堆栈溢出后我使用这个代码:

I'm a Core Data noob, working on my first iOS app. After much Stack Overflowing I'm using this code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"momd"];
if (!path) {
    path = [[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"mom"];
}
NSAssert(path != nil, @"Unable to find Resource in main bundle");

CoreData是我的应用程序的名称。

CoreData is the name of my app.

我试图通过在我的iPhone模拟器中找到sqlite文件的路径,然后去插入到sqlite文件中的初始数据到应用程序。但在某些时候,我移动了sqlite(认为它会创建一个新的副本),从模拟器中删除了该应用程序,并且sqlite文件去了。我不知道是否要退出过程的某些部分(这是几个小时前),但最终的结果是一切都搞砸了。

I've tried to put in initial data into the app by finding the path to the sqlite file in my iPhone simulator, and then going and inserting into that sqlite file. But at some point, I moved the sqlite (thinking it would create a fresh copy), deleted the app from the simulator, and the sqlite file is gone. I'm not sure if I'm leaving out some part of the process (this was a few hours ago) but the end result is that everything is screwed up.

如何重新确认这个sqlite / momd文件? 清除和清除所有目标都显示为灰色。

How do I resubstantiate this sqlite / momd file? "Clean" and "Clean all targets" are grayed out.

我很高兴在应用程序中发布相关代码,有大量的代码与Core Data相关,我不明白,所以我不知道什么部分发布!非常感谢任何帮助。

I'm happy to post the relevant code from my app that would help shed some light on this problem but there's tons of code relating to Core Data which I don't understand, so I'm not sure what part to post! Any help is greatly appreciated.

推荐答案

以下是一些建议:


  • 您发布以获得 .mom(d)文件的代码不是完全推荐的方法。请改用 mergedModelFromBundles ,如

  • The code you posted to get the .mom(d) file is not exactly the recommended way. Use mergedModelFromBundles instead, as in

self.managedObjectContent= [NSManagedObjectModel mergedModelFromBundles:nil];

它负责获取路径,选择/合并正确的 / code>或 momd ,并且通过一步初始化MOC。您使用此。但请注意,您需要暂时清理构建过程,如此SO问题/回答

It takes care of getting the path, choosing/merging the correct mom or momd, and initializing of the MOC all by one step. You should use this. But note that you need to clean the build process once in a while, as discussed in this SO question/answer.

这表明,虽然通过StackOverflow抓取通常是好的,但这不是最好的办法,当你处理一个像CoreData 。

This shows that, although crawling through StackOverflow is often good, that's not the best approach when you deal with a big framework like CoreData.

老实说,请花一天时间阅读文档从开始到结束。你可能想要google的代码和立即开始编码,但阅读文档肯定节省了开发时间从长远来看。

Honestly, take a day and read the documentation from the start to the end. You might want to google bits of code and to start coding immediately, but reading through the documentation definitely saves the development time considerably in the long run.

此外,Marcus Zarra的CoreData图书(请参阅此处 )帮助了我很多。

Also, Marcus Zarra's CoreData book (see here) helped me a lot. It might look expensive, but it was totally worth while.

在不同的主题上,我认为这是一个不错的策略, sqlite文件到模拟器的目录(〜/ Library / Application Support / iPhone Simulator / )甚至用于开发目的...因为它不能在真实设备上工作。如果你需要这样做,把sqlite文件作为应用程序的资源,并在启动时复制到 Documents Caches ,然后使用。

On a different topic, I don't think it a good strategy to put the pre-cooked sqlite file into the simulator's directory (inside ~/Library/Application Support/iPhone Simulator/) even for development purpose... because it doesn't work on the real device. If you need to do so, put the sqlite file as a resource of the app, and copy it at the launch time to either Documents or Caches, and use that afterwards.

这篇关于找不到momd文件:Core Data问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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