|
|
|
|
|
by TeamDman
598 days ago
|
|
Swift does apparently, here's an example from ChatGPT enum Animal {
case dog(name: String)
case cat(name: String)
case bird
func sound() {
switch self {
case .dog(let name):
print("\(name) says Woof!")
case .cat(let name):
print("\(name) says Meow!")
case .bird:
print("Tweet!")
}
}
}
and another with nesting enum Thing {
case first(x: Int)
case second
}
enum Outer {
case ok(Thing?)
}
let value: Outer = .ok(.some(.first(x: 42)))
switch value {
case .ok(.some(.first(let x))):
print("Matched with x = \(x)")
case .ok(.some(.second)):
print("Matched .second")
case .ok(.none):
print("Matched .none")
}
|
|
I still think it's a meaningful reason for Rust's popularity, though, given that Swift isn't used much outside of the Apple ecosystem.