How to specify #define commands for two different purposes

I have a project that I divide into two goals. In the original project, several define commands are used for the same purpose, however I need these values ​​to be different now, depending on what purpose I create.

What is the right way to do this? Should I use NStrings declared in AppDelegate? Or can I use the #if operator when #defines parameters?

Any help is greatly appreciated.

+4
source share
2 answers

One approach would be 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 the target preprocessor settings.

Usually you use GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS and not GCC_PREPROCESSOR_DEFINITIONS , because the latter may prevent the sharing of PCH headers.

To add this, follow the link:

  • Project Navigator β†’ Project β†’ Goal β†’ Build Settings

then drop GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS in the search field and set its value something like this: MON_TARGET_A $(inherited)

+3
source

You can add additional preprocessor macros to the target settings (Preprocessing-> Preprocessor Macros) and use #ifdef.

This is the most flexible approach.

0
source

Source: https://habr.com/ru/post/1395201/


All Articles