【发布时间】:2020-03-26 14:12:40
【问题描述】:
是否可以在 switch 语句中使用元组作为模式?
在下面的示例代码中,我想定义一个命名常量来表示要匹配的模式,在本例中为元组 (1,2)
let thing = 1
let otherThing = 2
let patternToMatchAgainst = (1,2)
switch (thing, otherThing) {
case patternToMatchAgainst: break // Expression pattern of type '(Int, Int)' cannot match values of type '(Int, Int)'
default: break
}
【问题讨论】:
标签: swift tuples pattern-matching