What's the correct syntax for using enum cases and guard to allow more-than-one case to proceed?
With a switch
we can use a case-item-list to combine switch cases.
Is there anything like that for guard
or if
statements?
Here's a code example of kinda-sorta what I'd like to do...
enum Thingy {
case one
case two
case three
}
func doSomething(with value: Thingy) {
switch value {
case .one, .three:
print("I like these numbers")
default:
print("Two")
}
}
// Doesn't compile
func doSomethingAlt(with value: Thingy) {
guard .one, .three = value else {
print("Two")
return
}
print("I like these numbers")
}