Here I have enum which I check in switch

 enum Action { case Walk(meters : Int) case Run(meters : Int, speed : Int) case Stop case Turn(direction : Direction) enum Direction { case Left case Right } } func checkAction (action : Action) { switch action { case Action.Run(let meters, let a) where meters < 32: print("Run \(a)", terminator : "") default: break } } 

This is how it works, but if I ask two conditions, it does not work

 case Action.Run(let meters, let a) where meters < 32, a < 22: print("Run \(a)", terminator : "") 

What am I doing wrong?

  • It seems to me that you first need to write code, so that it is clear where, what and how, and not spend a lot of time distributing blocks of code, and only then on the solution. I did not want to offend, if that) - ikerya
  • @ikerya did not understand anything from your not intelligible comment ... As for me there is nothing to explain here, there is an enum and there is a function that accepts it. In the switch function which, depending on the value, performs the actions. So my question is how to set two conditions in a switch case where similar to that described in the question. Read carefully the question if you wanted to be useful. Did not want to offend, if that) - Aleksey Timoshchenko

1 answer 1

Consider that where is equal to if. Correct entry:

 case Action.Run(let meters, let a) where meters < 32 && a < 22: print("Run \(a)", terminator : "")