Let's say that you have the code
if stringValue == "ab" || stringValue == "bc" || stringValue == "cd" { // do something }
Is there a way to shorten this condition or beautify it (preferably without using the switch statement)? I know that this code does NOT work:
if stringValue == ("ab" || "bc" || "cd") { // do something }
I've seen some complex solutions on other languages, but they seem language specific and not applicable to Swift. Any solutions would be appreciated.
let valuesArray = ["ab","bc","cd"] valuesArray.contains(str) // -> Bool
1.4m articles
1.4m replys
5 comments
57.0k users