Swift Language Tuples as Case in Switch


Example

Use tuples in a switch

let switchTuple = (firstCase: true, secondCase: false)
   
switch switchTuple {   
 case (true, false):
    // do something
 case (true, true):
    // do something
 case (false, true):
    // do something
 case (false, false):
    // do something
}

Or in combination with an Enum For example with Size Classes:

    let switchTuple = (UIUserInterfaceSizeClass.Compact, UIUserInterfaceSizeClass.Regular)
    
    switch switchTuple {
    case (.Regular, .Compact):
        //statement
    case (.Regular, .Regular):
        //statement
    case (.Compact, .Regular):
        //statement
    case (.Compact, .Compact):
        //statement
    }