简体   繁体   中英

Embed Core Data into a Static Library

I am trying to embed a core data model into a static library or a framework. I have stumbled upon a few tutorials and SO questions like this one . The process is to create a bundle target where you can embed the core data model file.

This is working fine, but it doesn't seem good enough for me. I have noticed that Google Analytics have implemented a static library that uses core data and all you have to add is headers and the .a file.

So my question is, how can we embed core data in a static library without having a bundle, just like Google Analytics?

You can create the model in code by instantiating instances of NSEntityDescription , NSPropertyDescription etc. This involves a lot of boiler plate code but it is relatively straight forward.

An alternative, which I can't recommend but will mention, is to include the ManageObjectModel in the binary in some form. It can then be extract to a temporary folder and read as per normal. ( Embedding Resource Files in a Cocoa Foundation Command Line Tool )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM