Checking for Presence of Objective-C Framework
Asked Answered
H

1

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?

Hanan answered 20/7, 2011 at 17:26 Comment(4)
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.Lucite
How about #ifdef _COREDATADEFINES_H ?Fraudulent
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).Piglet
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.Hanan
L
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.

Lucite answered 21/7, 2011 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.