In Swift the switch statement interval matches the tuple pattern
- 2020-05-15 02:14:31
- OfStack
Without further details, the following code introduces switch statement interval and tuple pattern matching, as follows:
// switch Generalized matching of
let x = 1000
// That is to say there is no image C Language as requirements switch This is followed by integer constants
switch x {
// case You can follow the interval
case 1...9:
print(" Single digits ")
case 10...99:
print("10 digits ")
case 100...999:
print(" Hundreds of digits ")
case 1000...9999:
print(" Thousands of digits ")
default:
print(" Do not conform to the ")
}
let point = (10, 10)
// switch You can follow it 1 Individual tuple types
switch point {
case (0, 0):
print(" Origin of coordinates ")
case (1...10, 1...10):
print("x and y The coordinate range is at 1-10 Between the ")
case(_, 0):
print(" Point in x On the shaft ")
default:
print(" other ")
}