concept nil in category swift

This is an excerpt from Manning's book Swift in Depth.
Third, the error handling is suboptimal and doesn’t fit the Swift model. Both the returned data and error can theoretically be filled or nil. The code doesn’t express that it can only be one or the other. We cover this in chapter 11.
Taking it one step further, you’ll get a look at how optionals and collections are affected with compactMap. You’ll see how you can filter nils while transforming collections-.
When you return nil from a flatMap operation, you end up with a regular nil value instead. Returning nil from a flatMap operation means that subsequent flatMap operations are ignored.
In the next example, you halve 5 and flatMap over it. You end up with a nil; the result is the same as starting with a nil (see figure 10.6).
When you have a nil optional, subsequent flatMap operations are ignored. Because you can return nil from the flatMap closure, you can short-circuit a chained operation.
In simpler terms, you can filter nils out of a collection. As you’ve seen before, not every String can be turned into a URL, resulting in an optional URL type, as in this example.
If you return nil from a flatMap, you can short-circuit operations.

This is an excerpt from Manning's book iOS Development with Swift.
If you have experience in other languages, you’re probably familiar with the absence of value—this concept is known in Swift as nil.
But wait, I said “a variable defined as a String can never contain a value that isn’t a String.” nil isn’t a String. Therefore, a variable defined as a String can never contain nil! Figure 2.7 illustrates what happens if you try to assign nil to a String.
The question is this: what sort of variable can be equal to nil? Swift introduces the optional type to address this question—and the billion-dollar mistake.
Unwrapping an optional refers to extracting its contents. There are two main techniques available for unwrapping an optional: forced unwrapping assumes the optional can’t contain nil, while optional binding (combined with an if or guard statement) performs a check.
Okay, you’ve twisted my arm—here’s the secret. Add an exclamation mark after the optional, and the optional will be unwrapped with the expectation that it will be the appropriate data type (that is, not nil).
print("Your \(main!.uppercased()) is served!")Use forced unwrapping with caution—you must be 100% certain that the variable can’t equal nil or you’ll cause a runtime error. How can you be certain that your variable isn’t equal to nil? Well, one way is to surround your forced unwrapping of an optional with an if statement verifying first that your optional contains a value: