Introducing optionals and optional binding
Up until now, every time you declared a variable or constant, you assigned a value to it immediately. But what if you want to declare a variable first and assign a value later? In this case, you would use optionals.
For more information on optionals, visit https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics.
Let's learn how to create and use optionals and see how they are used in a program. Imagine you're writing a program where the user needs to enter the name of their spouse. Of course, if the user is not married, there would be no value for this. In this case, you can use an optional to represent the spouse's name.
An optional may have one of two possible states. It can either contain a value or not contain a value. If an optional contains a value, you can access the value inside it. The process of accessing an optional's value is known...