How does 'switch' work? Not the same as if/else with pattern matching operator

Protocols aren't relevant; it's a problem with enumerations. I haven't seen it before.

struct S { static let instance = Self() }
enum E { case instance }

func ~= (_: S, _: Void) -> Bool { true }
func ~= (_: E, _: Void) -> Bool { true }

S.instance ~= () // compiles
if case S.instance = () { } // compiles
E.instance ~= () // compiles
if case E.instance = () { } // Cannot convert value of type '()' to specified type 'E'

Edit: Oh, interesting. I don't see how what you're trying to do can work, unless this gets fixed:

2 Likes