Optionals
suggest changeIntroduction
“ An optional value either contains a value or contains nil to indicate that a value is missing”
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 3.1 Edition).” iBooks. https://itun.es/us/k5SW7.l
Basic uses include an optional constant, if let and guard let to unwrap safely, case let in a switch, and the nil-coalescing operator (??) when a missing value should fall back to a default.
Syntax
- var optionalName: optionalType? // declare an optional type, defaults to nil
- var optionalName: optionalType? = value // declare an optional with a value
- var optionalName: optionalType! // declare an implicitly unwrapped optional
- optional! // force unwrap an optional
Remarks
For more information about optionals, see The Swift Programming Language.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents