我的 XCODE 项目中有一个名为 LINPHONE_DEBUG
的预处理器宏。在我的build设置中,我已将宏设置为 0
,就像这样:LINPHONE_DEBUG=0
。
但不知何故,当我使用这段代码时:
#if LINPHONE_DEBUG
foo()
#endif
foo()
仍被调用,请参见下面的屏幕截图。
你可以看到我打印了po LINPHONE_DEBUG
,结果是0
,但是还是到了code。
我正在运行 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#>.”
有关构建配置的更多信息,请参阅文档。
关于ios - XCode 预处理器宏 #if 仍然包含与符号定义为 0 相反的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32170906/