SwiftOptionals
Swift optionals are a feature that allows a variable to hold either a value of a specified type or no value at all. A type declared with a question mark, such as String? or Int?, denotes an optional. Internally, Optional is an enum with cases none and some(Wrapped). nil represents the absence of a value, and optionals are used to model missing data safely rather than using sentinel values.
Unwrapping is the process of accessing the underlying value from an optional. The usual patterns are optional
Swift provides optional chaining to call properties and methods on an optional; the expression evaluates to
Optionals extend to collection access, function return types, and error handling. They interact with standard library