Data Wrangling with Swift
Programming is all about making decisions. The purpose of most code involves taking information, inspecting it, making decisions, and producing an output. So far, we have seen a lot of ways to represent information, but in this chapter, we will explore how to make decisions based on that information, using a number of Swift’s control flow statements. We will find out how they differ and the situations where each is appropriate.
Once we’ve learned how Swift’s control flow works, we will have opened up a world of possibilities and paths for any information we wish to work with in Swift!
In this chapter, we will cover the following recipes:
- Making decisions with if/else
- Handling all cases with switch
- Looping with for loops
- Looping with while loops
- Handling errors with try, throw, do, and catch
- Checking upfront with guard
- Doing it later with defer
- Bailing out with fatalError and precondition