orthehelper
orthehelper

Reputation: 4079

Swift Compiler Flags Wont affect Objective-C code

under Active Compilation Conditions i have added a new flag (for debug only) called SOMEFLAG. the check is implemented like so and works great:

#if SOMEFLAG
   print("SOMEFLAG is true");
#endif

it actually prints like i would expect. now, i need to examine the same flag from Objective-C class and it never evaluates to true. any idea why? should i make this flag in other way? in general my goal is to be able to detect when it is executed from another target, the build is triggered from the cli. if there is other way that less limiting i would like to know.

thanks!

Upvotes: 1

Views: 421

Answers (1)

gmw
gmw

Reputation: 437

In Objective-C (and other C-like languages that use a preprocessor) the canonical way to check whether a symbol is defined would be using #ifdef, not #if. There is an #if directive in Objective-C, but it doesn't behave quite the same way as the Swift #if compiler directive.

Upvotes: 1

Related Questions