Confused with swift enumeration syntax

I am studying the book "Functional Swift" and there is a piece of code that I do not understand.

indirect enum Tree <Element: Comparable> {
    case Leaf
    case Node(Tree <Element>, Element, Tree <Element>)
}

extension Tree {
    init() {
        self = .Leaf
    }
    init(_ value: Element) {
        self = .Node(.Leaf, value, .Leaf)
    }
    var isEmpty: Bool {
        if case .Leaf = self {
            return true
        }
        return false
    }
}

let a = Tree<Int>()
let b = Tree<Int>(5)

a.isEmpty
b.isEmpty

      

That's if the .Leaf = self case , which confused me. Why is case not in a switch block , and why is it using assignment (=) rather than equation (==) in the condition expression. I know this means that if it is a .Leaf enum value then blablabla, but the syntax I really don't understand.

+3


source to share





All Articles