3 Cool new features of Swift 5.9

01. Using if and switch as expressions

Until Swift 5.9, the keywords if and switch could only be used as statements.

This meant that it wasn’t possible to directly assign the result of an if or a switch to a variable or to pass it as an argument.

if and switch can now be used as expressions!

This means that these awful nested ternary expressions can now be replaced by much more readable if conditions:

Website

Tags: Features Swift