Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

any way to chain == and || operands [duplicate]

Tags:

swift

I have a situation where I have to make a check like this:

if foo == a || foo == b || foo == c {
  //do stuff
}

is there any way to chain these operands into something smaller like IDK foo == a||b||c

like image 822
4oby Avatar asked Mar 12 '23 06:03

4oby


1 Answers

Try this:

if [a, b, c].contains(foo) {
   //do stuff
}
like image 116
Daniel Avatar answered Mar 27 '23 21:03

Daniel