app getting crashed while creating the managedObjectModel of Coredata

不想你离开。 提交于 2019-12-25 02:43:17

问题


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_;

}

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...


回答1:


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.

Have a look here.



来源:https://stackoverflow.com/questions/8724974/app-getting-crashed-while-creating-the-managedobjectmodel-of-coredata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!