1

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?

Community
  • 1
  • 1
streem
  • 9,044
  • 5
  • 30
  • 41

1 Answers1

1

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)

Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
  • Great, I hadn't actually realized that the `NSManagedObjectContext` was created at runtime with the compiled model file. – streem Oct 20 '14 at 13:10