作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
请看下面的 switch 语句。我正在寻找一种更快捷的方法来执行测试;像这样的东西:
case let .b(other) where .x = other // This does not compile
这可能吗?
enum MyEnum {
case a
case b(MyOtherEnum)
}
enum MyOtherEnum {
case x
case y
}
func check(value: MyEnum) {
switch value {
case let .b(other):
if case .x = other {
print("Got it!")
}
default:
break
}
}
最佳答案
如果您只对案例 MyEnum.b(.x)
感兴趣,没有其他cases 那么你也可以使用 if
和 case
模式:
func check(value: MyEnum) {
if case .b(.x) = value {
print("Got it!")
}
}
关于swift - 如何使用单个 case 语句检查枚举值及其关联的枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43746080/
我是一名优秀的程序员,十分优秀!