Reputation: 5207
As you can see, in my Active compilation conditions
I have 2 flags(or whatever it is called)
, A and B.
I have 2 targets, so the first target has flag A, the second target has flag B...
In code, I am trying to define a value depending on selected app target, but problem is that it never enters the #if
block, but always the #else
block.
I have been trying to solve this for hours, but nothing helped me. I also tried to put -D
in my flag name, tried to also define the A
and B
in Other Swift Flags
...
Nothing worked.
This is my simple code:
#if A
#define kId @"a1a2a3" //never executed.
#else
#define kId @"b1b2b3" //always executed. Weird thing is also that I put a breakpoint here but its never catched...
#endif
Upvotes: 1
Views: 2461
Reputation: 16966
Active Compilation Conditions are for Swift and are analogous to Preprocessor Macros in Objective-C/C/C++.
In C-based languages lines beginning with #
are preprocessor directives.
Since you are using Objective-C, to use #if
in your code the value of A
should be non-zero. If you only want to test whether A
is defined you may use #ifdef
instead. Define A=1
in the Preprocessor Macros
under Apple Clang - Preprocessing
.
Upvotes: 3