【发布时间】:2015-03-18 03:43:41
【问题描述】:
我已经在 Swift 中实现了一个带有计算属性的枚举语句。我想添加有条件编译的值,例如仅适用于某些配置。
这是我正在尝试做的一个示例:
enum Rows: Int
{
case Row1
case Row2
#if DEBUG
case Debug
#endif
var rowTitle: String
{
case Row1: return "Row 1"
case Row2: return "Row 2"
#if DEBUG
case Debug: return "Debug"
#endif
}
}
这似乎不受支持,因为我在 switch 语句中的 case 语句中收到以下错误消息:
“case”标签只能出现在“switch”语句中
有没有办法在 Swift 中做到这一点?
谢谢,
大卫
【问题讨论】:
标签: swift conditional-compilation