11

I am creating a framework right now that can work with CoreData if you would like. The framework has functionality outside of CoreData as well. How can I wrap all the CoreData specific code in IfDef's, checking if the CoreData framework is available?

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
cruffenach
  • 425
  • 5
  • 13
  • So you want your library to make the decision at compile time rather than runtime to use CoreData? This means if you distribute a library file you will have multiple version, and if you compile the code you have to remember to set defines in Build Settings or early enough in the build process. – Joe Jul 20 '11 at 18:10
  • 1
    How about `#ifdef _COREDATADEFINES_H` ? – Marcelo Alves Jul 20 '11 at 20:03
  • Sounds like the opposite - he wants to make the decision at run time on wether to use Core Data (based on its availability and user affirmation). – Perception Jul 20 '11 at 20:04
  • 1
    I'm worried I may have to release two separate frameworks. Right now I compile it with a NSManagedOjectContext category included and when I include it into a project a will get compiler errors unless I include the Core Data framework. I want to release one .framework which includes the NSManagedObjectContext category if CoreData is included and doesn't if not. Unfortunately since the framework is pre-compiled I worry I may have to release two different frameworks. – cruffenach Jul 20 '11 at 20:15

1 Answers1

10

What you will want to do is use a weak link to the CoreData foundation. Once you do that you can use runtime checks to make sure that CoreData is available. Constant variables can be checked for existence at runtime as well. If you were to use preprocessor (#if #ifdef) checks you would then have two separate framework versions to distribute with each release.

Community
  • 1
  • 1
Joe
  • 56,979
  • 9
  • 128
  • 135