• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

MagicalRecord在静态库加载数据模型

用户头像
it1352
帮助1

问题说明

我试图在静态库中使用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.

正确答案

#1

构建静态库为数据模型生成了一个编译的.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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbgjeh
系列文章
更多 icon
同类精品
更多 icon
继续加载