Target Preprocessor Macros are ignored by the preprocessor in Xcode Target Preprocessor Macros are ignored by the preprocessor in Xcode xcode xcode

Target Preprocessor Macros are ignored by the preprocessor in Xcode


If you want to do it like this in Swift, you should add a User-Defined setting named OTHER_SWIFT_FLAGS in your Build Settings like this:

OTHER_SWIFT_FLAGS user-defined setting

And then in your code you type:

#if TEST1// Debug#endif#if TEST2// Release#endif

I don't know why you need this, but it may be interesting to look into native Xcode Target, to use specific behavior for multiple apps with same root project. If this is what you want, you should look into an article this: AppCoda using Targets with Xcode.


Just go to target->Edit Scheme -> Run -> Info and check the Build Configuration. Now while adding the Preprocessor Macros in build setting just make sure you are adding the macro for correct build configuration and correct target.

≈

I tried by adding for both debug and release build as above for my target App (Test-ObjectiveC). So when i tried below code with this setting, u can see the syntax color accordingly.

enter image description here


I was able to make it work by setting "Target->Build Settings->All->Swift Compiler - Custom Flags -> Active Compilation Conditions".

XCode version 12.3