Optional Binding
Optional binding allows getting the value inside an optional. It is a variant of the if-statement.
If the optional contains a value, the first branch is executed and a temporary constant or variable is declared and set to the value contained in the optional; otherwise, the else branch (if any) is executed.
Optional bindings are declared using the if
keyword like an if-statement, but instead of the boolean test value, it is followed by the let
or var
keywords, to either introduce a constant or variable, followed by a name, the equal sign (=
), and the optional value.
Last updated