如何在框架中使用Core Data的ManagedObjectModel? [英] How to use Core Data's ManagedObjectModel inside a framework?

查看:250
本文介绍了如何在框架中使用Core Data的ManagedObjectModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的应用程序的特定部分迁移到框架中,以便可以在我的应用程序本身以及其中一个新的iOS 8小部件中使用它。这部分是处理Core Data中所有数据的部分。这是非常直接的移动一切,并访问它。我只是无法访问我的 momd 文件。

I'm trying to migrate a specific part of one of my apps into a framework so that I can use it in my app itself and in one of those fancy new iOS 8 widgets. This part is the one that handles all my data in Core Data. It's pretty straight forward to move everything over and to access it. I'm just having trouble accessing my momd file in there.

创建 NSManagedObjectModel 我仍然尝试加载 momd ,如Apple的代码模板所示:

When creating the NSManagedObjectModel I still try to load the momd as illustrated in Apple's code templates:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyApp" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

不幸的是, modelURL 停留 nil ,因此当访问具有此错误的Core数据堆栈时, MyApp 崩溃:

Unfortunately, modelURL stays nil and thus MyApp crashes when accessing the Core Data stack with this error:

2014-08-01 22:39:56.885 MyApp[81375:7417914] Cannot create an NSPersistentStoreCoordinator with a nil model
2014-08-01 22:39:56.903 MyApp[81375:7417914] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'

$ b

推荐答案

这篇关于如何在框架中使用Core Data的ManagedObjectModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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