How does Swift's #if tag work?

I've written some code that can be compiled differently depending using

#if ***
...
#else
...
#endif

I then set up two different project targets. In one target under Swift Compiler - Custom Flags / Active Compilation Conditions, I define ***. In the other, I don't.

Using the two project targets, I can compile the program two different ways.

However, if I introduce an error into a section of code that is going to be ignored, XCode reports an error and won't compile.

Does the compiler truly ignore code that is in a failed #if block or does the code end up in the compiled code with a runtime check to not run?

I made a simple test:

#if compiler(>=5)
print("Compiled with the Swift 5 compiler or later")
#endif
#if compiler(<5)
print("Compiled with the Swift 4 compiler or earlier")
#endif

With Swift 5, I get

Compiled with the Swift 5 compiler or later 

I introduced an error, removing the ending "

print("Compiled with the Swift 4 compiler or earlier)

I get compiler error:

Unterminated string literal

AFAIU, even though compiler will ignore in code, it is looked at preprocessing stage and causes to fail.

I found an interesting discussion here:

a conditionally compiled section of your code must be syntactically complete.

https://stackoverflow.com/questions/24003291/ifdef-replacement-in-the-swift-language

How does Swift's #if tag work?
 
 
Q