元组作为 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
}