I’m developing an Objective-C framework and I need to be able to build 2 different versions of that framework:
- The basic framework,
- The basic framework + some extra functionalities (some of which are written in Swift).
In the header of my framework, I expose my public headers like this:
#import <MyFramework/FrameworkPublicHeader1.h>
#import <MyFramework/FrameworkPublicHeader2.h>
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader1.h>
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader2.h>
So far, I created a second target for my framework with extra functionalities.
So I have my "basic framework" target with all the classes it needs referenced in the Build Phases tab of the target. And I have my "framework with extra functionalities" target, with a few more classes referenced in the Build Phases tab of the target.
When I want to build the "basic framework", I select my "basic framework" target, and I edit the header of the framework to import only what's needed:
#import <MyFramework/FrameworkPublicHeader1.h>
#import <MyFramework/FrameworkPublicHeader2.h>
//#import <MyFramework/FrameworkExtraFunctionalityPublicHeader1.h>
//#import <MyFramework/FrameworkExtraFunctionalityPublicHeader2.h>
When I want to build the "framework with extra functionalities", I select my "framework with extra functionalities" target, and I edit my framework header to import the headers I need:
#import <MyFramework/FrameworkPublicHeader1.h>
#import <MyFramework/FrameworkPublicHeader2.h>
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader1.h>
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader2.h>
It works, I can build both versions of the framework and use them in my iOS projects.
But I would like it to be simpler than having to edit my framework header every time I switch targets.
I tried to define a preprocessor macro "EXTRAFUNCTIONALITIES=1" in my target's build settings, in Apple Clang - Preprocessing and in Custom Compiler Flags, so that I could just have my framework header like this:
#import <MyFramework/FrameworkPublicHeader1.h>
#import <MyFramework/FrameworkPublicHeader2.h>
#if EXTRAFUNCTIONALITIES
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader1.h>
#import <MyFramework/FrameworkExtraFunctionalityPublicHeader2.h>
#endif
But even though it compiles, the framework cannot be used on my iOS projects anymore when I do that (I have "Unresolved identifier" errors when trying to compile the app that uses my framework).
What am I doing wrong? Is there an alternative solution to have my framework header expose different public headers depending on the target selected?