Shouldn't type associate on reference instead of its value?<br><br>I agree its syntax is a little suprise : dereferencing an optional without value doesn't throw an error.<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><div class="quote"><br><br>-------- 原始邮件 --------<br>主题:[swift-evolution] [Design Question] Unexpected forced optional        unwrapping behavior<br>发件人:Michael Henson via swift-evolution <swift-evolution@swift.org><br>收件人:swift-evolution <swift-evolution@swift.org><br>抄送:<br><br><br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I've spent some time exploring different aspects of the language's type system and came across a case where I wanted to know the type of the thing an optional might hold, if it exists. The direct type of an optional variable is, unsurprisingly, an optional:<div><br></div><div>&gt; var example: String? = "example"</div><div>example: String? = "example"</div><div>&gt; example.dynamicType</div><div>$R1: String?.Type = String?</div><div><br></div><div><br></div><div>Ok, that didn't work. What if I dereference?</div><div><br></div><div>&gt; example!.dynamicType</div><div>$R2: String.Type = String</div><div><br></div><div>Ok. What if the optional doesn't currently have a value? Does this still work?</div><div><br></div><div>&gt; example = nil</div><div>$R3: String.Type = String</div><div><br></div><div>That's odd. I expected it not work, given how forced unwrapping of nil optionals usually turns out.</div><div><br></div><div>Is this explicitly intended behavior, something that really shouldn't work and shouldn't be relied on, or... other?</div><div><br></div><div>Mike</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=zv-2Fta8zZnJ-2BWwISX5RHdd79su-2FjoebtLz43a4s-2BYOw24l00sRKbtvTtNHn-2BfZoRwMiCNI9uqxadbKp4Ee5-2Ft2IbQyrHmkwEOVm0E6uSK3K52mKL12G4O3j9wlZsCe2eF4BKgFx9gsNI43gyuFwfKhTD8FWFNY4wBzlaRt0RGa9-2B24ZojzjBdvHjqU-2FFfybYc2wdZ2fX7JJuSYiFwoBuZ0kEG7sJk0n5fwLxC29ZF8Bs-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</blockquote></swift-evolution@swift.org></swift-evolution@swift.org></div></body></html>