In Appleās Swift language switch statements must be what apple calls āexhaustiveā. Iāve felt the term to be very literal. Literally exhaustive?
Example that does not work:
let count = 42
switch count {
case 1:
print(1)
case 7:
print(7)
}
The above statement does not work because itās missing a default
case. Why? What if I donāt want to do anything else? Why do I need to write something that wonāt be used? Donāt worry, there is an amazing and less āexhaustiveā way to handle these situations; simply default: ()
Correct example:
let count = 42
switch count {
case 1:
print(1)
case 7:
print(7)
default: ()
}