3

I want to have a bool macros to enable some functionality in my app per build. For example, enable in QA builds but disable in production. For this, I added this code to my app .xcconfing file:

FEATURE_ENABLED=1

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) FEATURE_ENABLED='${FEATURE_ENABLED}'

OTHER_SWIFT_FLAGS = $(inherited) -DFEATURE_ENABLED='${FEATURE_ENABLED}'
#if FEATURE_ENABLED
// do some stuff
#else
// do some other stuff
#endif

FEATURE_ENABLED is working in ObjC when I change its value, but not working in Swift at all. The question is why, and how to make it work.

Roman Simenok
  • 510
  • 7
  • 21
  • 2
    `SWIFT_ACTIVE_COMPILATION_CONDITIONS = ENABLE_FEATURE;` ? Swift flags actually don't care about the value, you cannot turn them off by setting `0`. – Sulthan Feb 01 '19 at 19:40
  • 1
    Also [Using compiler variables in Swift](https://stackoverflow.com/questions/27804227/swift-using-compile-variables) – jscs Feb 01 '19 at 20:05
  • @Sulthan Thank you for the help, this does the trick for debug builds. But I need value in swift, and it seems that I should find another solution, with `.plist` probably. – Roman Simenok Feb 01 '19 at 23:17
  • @JoshCaswell Thank you for the links, las one had the answer to my question. – Roman Simenok Feb 01 '19 at 23:19
  • Glad I could help, would you please confirm that by clicking the "flag" link, choosing "duplicate", and pasting in the link? – jscs Feb 01 '19 at 23:22

0 Answers0