Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

ios

swift

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"

like image 422
leo_luck Avatar asked May 05 '16 08:05

leo_luck


People also ask

What is Flag in Swift?

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.

What is compilation conditions Swift?

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. (

How do I add a compiler flag in Xcode?

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.


1 Answers

-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...

like image 138
Alex Curylo Avatar answered Oct 22 '22 19:10

Alex Curylo