Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "case" mean without switch statement in Swift?

Tags:

I ran into this code which is part of a Swift implementation of a linked list in the Swift Algorithm Club. Throughout the implementation the author uses case let following a while statement right before unwrapping an optional. I've never seen the case keyword used outside of the context of a switch statement, and I'm wondering what exactly it does? Does it somehow cast the let next? = node.next part to true or false, maybe depending on whether next? becomes nil or not?

public var last: Node? {
    if var node = head {
        while case let next? = node.next {
            node = next
        }
        return node
    } else {
        return nil
    }
}