skip to Main Content

After reading this stackoverflow post, I tried to introduce macros in my project.
I have the following code in a sample macOS CommandLine tool.

#if         ELDIABLO
NSLog ("ELDIABLO macro detected!")
#else
NSLog ("ELDIABLO macro not detected!")
#endif

The ELDIABLO macro is declared in Target->BuildSettings->SwiftCompiler/OtherSwiftFlags (prefixed with -D).

This works.

SwiftMacros[73110:12048088] Detected ELDIABLO macro!!

Now, when I transferred the same concept to my original project it doesn’t work. I always get

ELDIABLO macro not detected!

According to another stackoverflow post, the macros should be defined in Target->BuildSettings->SwiftCompiler/ActiveCompilationConditions (without -D prefix).
I tried that too, but didn’t work.

What’s wrong here? What am I missing?

I’m using Xcode 13.4.
My project structure: One target (the app) dependent on many other targets (static libs). All macro settings are applied to the app target (not to the static libs).

2

Answers


  1. Chosen as BEST ANSWER

    I was setting the macro in the app target, but the code which uses macro is one of the other targets i.e static libs, though the static libs targets are added as a dependency for the app target.

    After adding the macro to the static lib target, it works.


  2. That means the macro didn’t find your "Condition setting", ex: ELDIABLO

    So now you need to open your Project/[Your in-use target]/Build Settings.
    Then, search the setting with the keyword: "active compilation". And, put your CONDITION_CONFIG here. One line for one CONDITION_CONFIG.

    Check image below:Macro key setting

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search