Swift can a switch case statement have multiple arguments?
Yes, take a look at Swift's documentation on switch
statement.
In order to achieve what you want, you need to check for the current value of myLetters
:
var myCondition: Bool {
switch self {
case .a, .b: return true
case .c: return false
}
}
If you want to group cases with the same assosiated value, you can do the following:
var myCondition: Bool {
switch self {
case .a(let value), .b(let value): return value
case .c(let value1, let value2): // do stuff with value1 and value 2
}
}
Unfortunately you can't currently combine the let
statements to a single one.