元組作為 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
}

或者與 Enum 結合使用例如 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
    }