应用程序在创建Coredata的managedObjectModel时崩溃 [英] app getting crashed while creating the managedObjectModel of Coredata

查看:194
本文介绍了应用程序在创建Coredata的managedObjectModel时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从以下代码创建一个managedObjectModel对象

I am creating a managedObjectModel object from the following code

- (NSManagedObjectModel *)managedObjectModel {

if (managedObjectModel_ != nil) {
    return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"DataHouse" ofType:@"momd"];

NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

return managedObjectModel_;

}

DataHouse.xcdatamodeld 文件。这段代码工作绝对正常。现在,来到这个问题....我通过以下中创建了 frawework -framework-iphone-ios-2-0 /#list_contentsrel =nofollow>这个美好的链接。我已经包括我的框架在一个新的项目,并试图运行它。应用程序崩溃了我完全在上面的代码库。我知道它的原因,但无法解决它。这里的问题是,在创建managedObjectModel时,编译器会在主包中查找名为DataHouse.xcdatamodeld的文件。但这个文件是新的framrwork的一部分,并不存在于主包。现在,我应该怎么解决这个问题..任何想法请...

i have DataHouse.xcdatamodeld file in my xcode project. This code is working absolutely fine. Now, coming to the problem.... I have made a frawework out of my code by following this wonderful link. i have included my framework in a new project and tried running it. The app crashed on me exactly in the above code base. I know the reason for it too but unable to resolve it. The problem here is that while creating the managedObjectModel, the compiler is looking for the file called DataHouse.xcdatamodeld in the Main bundle. but this file is a part of the new framrwork and is not present in the main bundle. Now, how am i supposed to solve this problem.. Any ideas please...

推荐答案

NSBundle 加载包而不是 mainBundle 。使用它们,您应该能够指定正确的软件包位置。

There are several other class methods on NSBundle to load a bundle instead of mainBundle. With them, you should be able to specify the correct bundle location.

查看此处

这篇关于应用程序在创建Coredata的managedObjectModel时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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