<div dir="ltr">Here are two implementations that I&#39;d expect to be equivalent, but something&#39;s different because the first example crashes, whereas the second example does not crash.<div><br></div><div>What&#39;s the difference between these two? Why does casting to Any before the forced downcast to T have any effect?</div><div><br></div><div>Example 1: (<font face="monospace">`unexpectedly found nil while unwrapping an Optional value`</font>)</div><div><font face="monospace">```</font></div><div><div><font face="monospace">func cast&lt;T&gt;(_ name: String?) -&gt; T {</font></div><div><font face="monospace">    return name as! T</font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">debugPrint((cast(nil) as String?) as Any))</font></div></div><div><font face="monospace">```</font></div><div><br></div><div>Example 2: (prints <font face="monospace">`nil`</font>)</div><font face="monospace">```<br>func cast&lt;T&gt;(_ name: String?) -&gt; T {<br>    return (name as Any) as! T<br>}<br><br><br>debugPrint((cast(nil) as String?) as Any)</font><div><font face="monospace">```</font></div></div>