XCode 预处理器宏 #if 仍然包含与符号定义为 0 相反的代码
XCode Preprocessor macro #if still includes code contrary that the symbol is defined to 0
我的 XCODE 项目中有一个名为 LINPHONE_DEBUG
的预处理器宏。在我的构建设置中,我将宏设置为 0
完全像这样:LINPHONE_DEBUG=0
.
但是当我使用这段代码时不知何故:
#if LINPHONE_DEBUG
foo()
#endif
foo()
仍然被调用见下面的截图。
你可以看到我打印了po LINPHONE_DEBUG
,是0
,但是还是到了代码
我是运行XCODE 6.4 (6E35b)
.
来自 Swift iBook:将 Swift 与 Cocoa 和 Objective-C 结合使用(Swift 2 Prerease)
“The Swift compiler does not include a preprocessor. Instead, it takes advantage of compile-time attributes, build configurations, and language features to accomplish the same functionality. For this reason, preprocessor directives are not imported in Swift.”
“Build Configurations
Swift code and Objective-C code are conditionally compiled in different ways. Swift code can be conditionally compiled based on the evaluation of build configurations. Build configurations include the literal true and false values, command line flags, and the platform-testing functions listed in the table below. You can specify command line flags using -D <#flag#>.”
有关生成配置的详细信息,请参阅文档。
更新:此解决方案适用于 objective c。
你应该这样尝试:
#if LINPHONE_DEBUG > 0
foo()
#endif
您可以通过将环境配置放入结构中来避免预处理器指令:
我的 XCODE 项目中有一个名为 LINPHONE_DEBUG
的预处理器宏。在我的构建设置中,我将宏设置为 0
完全像这样:LINPHONE_DEBUG=0
.
但是当我使用这段代码时不知何故:
#if LINPHONE_DEBUG
foo()
#endif
foo()
仍然被调用见下面的截图。
你可以看到我打印了po LINPHONE_DEBUG
,是0
,但是还是到了代码
我是运行XCODE 6.4 (6E35b)
.
来自 Swift iBook:将 Swift 与 Cocoa 和 Objective-C 结合使用(Swift 2 Prerease)
“The Swift compiler does not include a preprocessor. Instead, it takes advantage of compile-time attributes, build configurations, and language features to accomplish the same functionality. For this reason, preprocessor directives are not imported in Swift.”
“Build Configurations Swift code and Objective-C code are conditionally compiled in different ways. Swift code can be conditionally compiled based on the evaluation of build configurations. Build configurations include the literal true and false values, command line flags, and the platform-testing functions listed in the table below. You can specify command line flags using -D <#flag#>.”
有关生成配置的详细信息,请参阅文档。
更新:此解决方案适用于 objective c。
你应该这样尝试:
#if LINPHONE_DEBUG > 0
foo()
#endif
您可以通过将环境配置放入结构中来避免预处理器指令: