其他Swift标志中的“-D”的含义是什么?

7
在Xcode的构建设置中,我们总是在“其他Swift标志”中使用“-D XX”。 "-D"的目的和正确使用方式是什么?
如果不使用前缀“-D”,会有什么结果?
2个回答

8
-D表示你定义的标识符,可用于构建配置语句,如内置的os()、arch()和swift()。
请参阅苹果文档:Swift编程语言:语句

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


2

-D定义一个宏,供预处理器使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接