Chapter 4. To Be or Not to Be – Optionals
As discussed in Chapter 2, Building Blocks – Variables, Collections, and Flow Control, all variables and constants must always have a value before they are used. This is a great safety feature because it prevents you from creating a scenario where you forget to give a variable an initial value. It may make sense for some number variables, such as the number of sandwiches ordered to start at 0, but it doesn't make sense for all variables. For example, the number of bowling pins standing should start at 10 and not at 0. In Swift, the compiler forces you to decide what the variable should start with instead of providing a default value that could be wrong.
However, there are other scenarios where you will need to represent the complete absence of a value. A great example for this is when you have a dictionary of word definitions and you try to look up a word that isn't in the dictionary. Normally, this will return a...