我试图在静态库中使用MagicalRecord与数据模型。 当我调用
I'm trying to use MagicalRecord with a data model in a static library. When I just call
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"db.sqlite"];在库中,似乎没有加载数据模型。调用
in the library, it doesn't seem to load the data model. A call to
[TheObject MR_createEntity];会抛出异常:
could not locate an entity named 'TheObject' in this model.'如何加载我想要使用的模型? 项目布局概述:
How do I load the model I want to use? An overview of the project layout:
我试图默认从主包中加载模型?
I figure MR tries to load the model from the main bundle by default?
[MagicalRecord setDefaultModelNamed:@"TheModel.xcdatamodeld"];也不会找到它。 如果我尝试将库的模型资源文件复制到主项目,Xcode会崩溃。
will also not find it. And if I try to copy the library's model resource file into the main project, Xcode complains by crashing.
推荐答案构建静态库为数据模型生成了一个编译的.mom文件。 (打开lib的Products组,右键单击编译的lib,在Finder中显示)此文件可以添加到主项目的资源,使其在主包中可用。
building the static library produced a compiled .mom file for the data model. (open the lib's Products group, right click the compiled lib, show in Finder) this file can be added to the main project's resources, making it available in the main bundle.
更多推荐
MagicalRecord在静态库中:如何加载数据模型?
发布评论