Member-only story
Switch Statements using Swift
Press the switch on or off
4 min readFeb 6, 2020
Here the image of a Switch
represents two states, either on or off. In Swift Switch
statements allow us to have an alternative to If
statements to choose between two (or more) options.
Although Switch
statements are relatively easy, there are a number of prerequisites for this article. Make sure you read up, and then get going on this guide!
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- Be able to produce a “Hello, World!” iOS application (guide HERE)
- Protocols in Swift (guide HERE)
- A grasp of enum would be useful (guide HERE)
- It would be useful to be familiar with String Interpolation (guide HERE)
- Tuples are featured later on, but you are shown how to create them, and underscores are used to ignore Tuple Components (guide HERE)
- Networking responses are mentioned, but this is only to give context and is not essential to this guide
Terminology
Enum: A type consisting of a set of named values, called members
Fallthrough: Fall through the bottom of each case and into the next one