I have a project I am splitting into two targets. The original single-target project uses a number of define commands, however I need these values to now be different depending on which target I am building.
What's the correct way to do that? Should I be using NStrings declared on the AppDelegate? Or can I use a #if statement when settings the #defines?
Any help, much appreciated.
One approach would be like this:
#if defined(MON_TARGET_A)
#define MON_TARGET_NAME "App A"
#elif defined(MON_TARGET_B)
#define MON_TARGET_NAME "App B"
#else
#error "which target are you building?"
#endif
Then add MON_TARGET_A
or MON_TARGET_B
to your target's preprocessor settings.
Usually, you'll use GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
and not GCC_PREPROCESSOR_DEFINITIONS
because the latter can prevent sharing of PCH headers.
To add this, go to:
then drop GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
into the search field and set its value to something like: MON_TARGET_A $(inherited)
You can add additional preprocessor macros in your target settings (Preprocessing->Preprocessor Macros) and use #ifdef.
This is the most flexible approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With