Search code examples
xcodetargetconditional-compilation

Preprocessor Macro not able to work as expected


I defined "Preprocessor Macro" FREEVERSION=0 on Main target, FREEVERSION=1 on Lite target.

then in AppDelegate

#ifdef FREEVERSION
@import GoogleMobileAds;
#endif

When I build for Lite target it runs ok. But when I build for Main target, it says error there on import. I expect the compiler to ignore these when I select Main target. But no.Why?


Solution

  • Guess I am answering my own question. #ifdef checks for existence of the the macro. But not the value. In this case both targets have FREEVERSION defined hence evaluates to true for both. To fix it, simply remove the entry FREEVERSION=0 in Main target altogether. And the value don't matter.