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"
Feature toggles (also known as feature flags) are one way. They provide app developers with a way to add new behavior to an application and then enable or disable it without deploying a new release.
Active Compilation Conditions is a new build setting for passing conditional compilation flags to the Swift compiler. Each element of the value of this setting passes to swiftc prefixed with -D , in the same way that elements of Preprocessor Macros pass to clang with the same prefix. (
Select your project in the project navigator in the left-hand panel, select your target, then select Build Phases. Expand Compile Sources and double-click the file you want to set the compiler flag for. Repeat for each target you want the changes to apply to. Save this answer.
-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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With