What is an optional value in Swift?

An optional in Swift is a type that can hold either a value or no value. Optionals are written by appending a ? to any type: var name: String? = “Bertie” Optionals (along with Generics) are one of the most difficult Swift concepts to understand. Because of how they are written and used, it’s easy … Read more

Uses for Optional

The main design goal of Optional is to provide a means for a function returning a value to indicate the absence of a return value. See this discussion. This allows the caller to continue a chain of fluent method calls. This most closely matches use case #1 in the OP’s question. Although, absence of a … Read more