'What's the meaning of "-D" in other swift flags

In Xcode's Build Settings, we always use "-D XX" in "Other Swift Flags". Whats the purpose and the proper use of "-D"?

And what's the result if we don't use the prefix "-D"



Solution 1:[1]

-D denotes an identifier you define for use with build configuration statements like the builtins os(), arch(), and swift().

See Apple documentation: Swift Programming Language: Statements

A build configuration statement allows code to be conditionally compiled depending on the value of one or more build configurations.

Every build configuration statement begins with #if and ends with #endif. A simple build configuration statement has the following form:

#if build configuration
  statements
#endif

Unlike the condition of an if statement, the build configuration is evaluated at compile time. As a result, the statements are compiled and executed only if the build configuration evaluates to true at compile time.

The build configuration can include the true and false Boolean literals, an identifier used with the -D command line flag, or any of the platform or language-version testing functions listed in the table below...

Solution 2:[2]

-D defines a macro to be used by the preprocessor

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 ha100