3 Cool new features of Swift 5.9

<h2>01. Using if and switch as expressions</h2> <p>Until Swift 5.9, the keywords&nbsp;<strong>if</strong>&nbsp;and&nbsp;<strong>switch</strong>&nbsp;could only be used as statements.</p> <p>This meant that it wasn&rsquo;t possible to directly assign the result of an&nbsp;<strong>if</strong>&nbsp;or a&nbsp;<strong>switch</strong>&nbsp;to a variable or to pass it as an argument.</p> <p><img alt="" src="https://miro.medium.com/v2/resize:fit:700/1*wCH9zA6oUc0Aa8EYYzlStg.png" style="height:198px; width:700px" /></p> <p><strong>if</strong>&nbsp;and&nbsp;<strong>switch</strong>&nbsp;can now be used as expressions!</p> <p>This means that these awful nested ternary expressions can now be replaced by much more readable&nbsp;<strong>if</strong>&nbsp;conditions:</p> <p><a href="https://medium.com/@sagar.ajudiya/cool-new-features-of-swift-5-9-71c4cc3b079c"><strong>Website</strong></a></p>
Tags: Swift Features