Swift Switch And If Expressions
Swift 5.9 allows if and switch statements to be used as expressions.
This enables the return of a value from these statements or their assignment to a variable.
For example, a switch expression can be used to determine the last path component of a URL associated with an enum state.
However, each branch of the if or each case of the switch must be a single expression.
Additionally, the if statement must include an else and return the same type from all branches.
These limitations somewhat restrict the usefulness of if and switch expressions.
The compiler may require type specification in some cases.
To learn more about these expressions, refer to SE-0380.