Beautify Code Without Optionals in Swift

<p>Optionality, while safe, can provide us with multiple issues that we need to handle and/or compensate for.</p> <p>I&rsquo;ll be going through ways of handling optionals within function returns here so that whoever needs to consume it doesn&rsquo;t have to deal with optionals. They can be applied to other areas, though. I&rsquo;ll walk you through from bad to good, and at the end, we will see two different ways of handling this that I would consider best practice.</p> <h1>Force Unwrap</h1> <p>Looking at this code here, it&rsquo;s quite unsafe if the section string passed in isn&rsquo;t in the Dictionary. When you force unwrap, you&rsquo;re saying you expect this to not be nil and to be around however, if it is nil, it will crash your application.</p> <p><a href="https://betterprogramming.pub/beautify-code-without-optionals-in-swift-e01dc279ffd1"><strong>Click Here</strong></a></p>
Tags: Beautify Code