MagicalRecord在静态库中:如何加载数据模型? [英] MagicalRecord in a static library: how do I load the data model?

查看:200
本文介绍了MagicalRecord在静态库中:如何加载数据模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在静态库中使用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在静态库中:如何加载数据模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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