I was hoping enum case assoc'ed value can have default like func parameter. Didn't find that but:
enum Foo {
case a(Int = 1) // what's this? why is .a => (Int) -> Foo
}
let x = Foo.a
print("type(of: x):", type(of: x), ", x:", x) // type(of: x): (Int) -> Foo , x: (Function)
let y = x(123)
print("type(of: y):", type(of: y), ", y:", y) // type(of: y): Foo , y: a(123)
Don't see this cover in the language guide enum section: Enumerations — The Swift Programming Language (Swift 5.7)
So why is .a
is a closure? What's this useful for?
And for my original question: can enum case associated value have default?