Range Matching
Values in switch cases can be checked for their inclusion in a range. This example uses
number ranges to provide a natural-language count for numbers of any size:
let count = 3_000_000_000_000
let countedThings = "stars in the Milky Way"
var naturalCount: String
switch count {
case 0:
naturalCount = "no"
case 1...3:
naturalCount = "a few"
case 4...9:
aturalCount = "several"
10...99:
aturalCount = "tens of"
100...999:
aturalCount = "hundreds of"
1000...999_999:
aturalCount = "thousands of"
ult:
aturalCount = "millions and millions of"
("There are (naturalCount) (countedThings).")