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’ll be going through ways of handling optionals within function returns here so that whoever needs to consume it doesn’t have to deal with optionals. They can be applied to other areas, though. I’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’s quite unsafe if the section string passed in isn’t in the Dictionary. When you force unwrap, you’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>