0
这可能吗?Swift关联枚举使用参数在fallthrough
switch type {
case let .dog(say): fallthrough
case let .cat(say):
print(say)
}
这不是有效的快速枚举,但有没有办法做到这一点? 基本上我的枚举都有相同的大小写操作,但参数值会有所不同。
这可能吗?Swift关联枚举使用参数在fallthrough
switch type {
case let .dog(say): fallthrough
case let .cat(say):
print(say)
}
这不是有效的快速枚举,但有没有办法做到这一点? 基本上我的枚举都有相同的大小写操作,但参数值会有所不同。
switch type {
case .dog(let say), .cat(let say):
print(say)
}
有趣的是,这并没有与斯威夫特2.工作 - 这是一个类似的问题http://stackoverflow.com/questions/33654074/fallthrough-in-a-switch-case-with-variable-declaration- in-swift(关闭作为http://stackoverflow.com/questions/30545503/swift-switch-case-with-multiple-patterns-cannot-bind-to-variable)的副本,所以这可能需要一个新的答案Swift 3. –
@MartinR它在Swift 3中实现:https://github.com/apple/swift-evolution/blob/master/proposals/0043-declare-variables-in-case-labels-with-multiple-patterns。 MD – Alexander