MagicalRecord in a static library: how do I load the data model?

拈花ヽ惹草 提交于 2019-12-12 04:14:25

问题


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

will throw an exception:

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"];

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:


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.



来源:https://stackoverflow.com/questions/13181662/magicalrecord-in-a-static-library-how-do-i-load-the-data-model

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