I'm able to build, launch, and debug my Swift app on an iPad from XCode, with a scheme that uses the Debug configuration. If I edit the scheme to use the Release configuration, the build is different, as expected, because in the console it then says my app "was compiled with optimization - stepping may behave oddly; variables may not be available." Fine.
What I don't understand is why regardless of which configuration is in use in the scheme, code inside of #if DEBUG blocks is never executed, e.g.
That's despite the fact that in my project settings, under Apple Clang - Preprocessing/Preprocessor Macros, it shows 1=DEBUG on the Debug line (and not on the Release line, as expected).
Why then does Swift behave as if DEBUG is never defined, regardless of the scheme's configuration? And what do I need to do in order to have debug-only code controlled by
P.S. I know that #if/#else/#endif is an anti-pattern, but even Apple says to use it, e.g. in this presentation from WWDC 2020, at 16:29:
Introducing StoreKit Testing in Xcode
P.P.S #ifdef DEBUG works no better than #if DEBUG
What I don't understand is why regardless of which configuration is in use in the scheme, code inside of #if DEBUG blocks is never executed, e.g.
Code Block #if DEBUG print("This never gets printed") #else print("this always executes instead") #endif
That's despite the fact that in my project settings, under Apple Clang - Preprocessing/Preprocessor Macros, it shows 1=DEBUG on the Debug line (and not on the Release line, as expected).
Why then does Swift behave as if DEBUG is never defined, regardless of the scheme's configuration? And what do I need to do in order to have debug-only code controlled by
Code Block #if DEBUG
blocks? Is there a Swift-lang setting I'm missing?P.S. I know that #if/#else/#endif is an anti-pattern, but even Apple says to use it, e.g. in this presentation from WWDC 2020, at 16:29:
Introducing StoreKit Testing in Xcode
P.P.S #ifdef DEBUG works no better than #if DEBUG