ios - XCode 预处理器宏 #if 仍然包含与符号定义为 0 相反的代码

标签 ios xcode swift macros

我的 XCODE 项目中有一个名为 LINPHONE_DEBUG 的预处理器宏。在我的build设置中,我已将宏设置为 0,就像这样:LINPHONE_DEBUG=0

但不知何故,当我使用这段代码时:

#if LINPHONE_DEBUG
    foo()
#endif

foo() 仍被调用,请参见下面的屏幕截图。

enter image description here

你可以看到我打印了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/

相关文章:

ios - 在 tableView cellForRow containsHit 方法之前访问 Algolia InstantSearch 命中

ios - 适用于 IOS 的 Flutter 应用程序,是否可以在不使用 Xcode 的情况下设置 IOS "Legacy Build System"?

ios - 强制 View Controller 的方向

swift - 如何在 Swift 中只执行一次代码?

ios - 可选类型 UILabel 的值未展开。

ios - 无法以沙盒用户身份购买 IAP

ios - Swift:使用核心数据更新一行[indexPath.row]

xcode - 重新排序框架的经验法则?

ios - 在 iOS 中以 2x 或 3x 读取图像

iphone - 埃塞俄比亚 unicode 在 iPhone 模拟器上显示为方框