【发布时间】:2016-06-10 01:26:32
【问题描述】:
我遇到了这段代码,它是Swift Algorithm Club 中链表的 Swift 实现的一部分。在整个实现过程中,作者使用case let,紧跟在一个while 语句之后,然后再展开一个可选项。我从未见过在 switch 语句的上下文之外使用 case 关键字,我想知道它到底是做什么的?它是否以某种方式将let next? = node.next 部分转换为true 或false,可能取决于next? 是否变为nil?
public var last: Node? {
if var node = head {
while case let next? = node.next {
node = next
}
return node
} else {
return nil
}
}
【问题讨论】: