Switch it up
Switch statements allow you to control the flow of execution by testing one specific value in multiple ways. In Objective-C, and other languages, Switch statements can only be used on values that can be represented by an integer, and are most commonly used to make decisions based on enumeration cases.
As we have seen, enumerations have become a lot more powerful in Swift, as they can be based on more than just integers, and so too can switch statements.
Switch statements in Swift can be used on any type and have advanced pattern-matching functionality, as we will see.
Getting ready
If you are old enough to remember the early days of the home computer, you may also remember text-based adventures. These were simple games that usually described a scene and then let you move around by typing if you want to move north, south, east, or west. You would find and pick up items, and could often combine them to solve puzzles.
How to do it...
Let's create parts of a text-based adventure to see...