How to do if pattern matching with multiple cases?

后端 未结 3 1510
一整个雨季
一整个雨季 2020-12-06 10:20

I\'m searching for the syntax to do pattern matching with multiple cases in an if case statement. The example would be this:

enum Gender {
    case Male, Fem         


        
3条回答
  •  温柔的废话
    2020-12-06 10:36

    For pattern matching, what you describe will not work yet. You could do this in your case. But if it cannot be convert into a hashValue. Then this would not work either.

    // Using Pattern Matching for more than one case.
    if case 0...2 = a.hashValue {
        print("Hello")
    }
    
    //Normal if else
    if a == .Male || a == .Female {
        print("Hello")
    }
    

提交回复
热议问题