<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Case .none:</div><div>Case .some("string"):</div><div><br></div><div><br>On Jun 28, 2016, at 06:40, Lucas Jordan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Forgive me if this was/is discussed already, I am new to the process here....<div><br></div><div>(code is attached as a playground too)</div><div><br></div><div><br></div><div><br></div><div>Sometimes when I am working with a String? nil can be a reasonable value, and what I want to do is something like the following:</div><div><br></div><div>







<p class=""><span class="">import</span><span class=""> UIKit</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">var</span><span class=""> str:</span><span class="">String</span><span class="">? = </span><span class="">"Hello, playground"</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">switch</span><span class=""> </span><span class="">str</span><span class="">{</span></p>
<p class=""><span class="">case</span><span class=""> </span><span class="">nil</span><span class="">:</span></p>
<p class=""><span class="">&nbsp; &nbsp; </span><span class="">print</span><span class="">(</span><span class="">"Nil!"</span><span class="">)</span></p>
<p class=""><font color="#ff9900"><span class="">case</span><span class=""> </span><span class="">"Hello, playground"</span><span class="">: &nbsp;</span><span class="">//it would be super nice if this worked.</span></font></p>
<p class=""><span class="">&nbsp; &nbsp; </span><span class="">print</span><span class="">(</span><span class="">"Match"</span><span class="">)</span></p>
<p class=""><span class="">default</span><span class="">:</span></p>
<p class=""><span class="">&nbsp; &nbsp; </span><span class="">print</span><span class="">(</span><span class="">"Some other non nil value?"</span><span class="">)</span></p>
<p class=""><span class="">}</span></p></div><div><br></div><div><br></div><div>But it does not work, the orange &nbsp;text is a compile time error, "Expression pattern of type 'String' cannot match value of type 'String?'. I realize that this can be replaced with a let statement (<span class="">case</span><span class=""> </span><span class="">let</span><span class=""> s </span><span class="">where</span><span class=""> s == </span><span class="">"Hello, playground"</span><span class="">:</span>), but that is verbose.&nbsp;</div><div><br></div><div>Seems like the compiler could be OK with the orange text, since it is clearly not nil.</div><div><br></div><div>Thoughts?</div><div><br></div><div>-Lucas</div><div><br></div><div><br></div><div><br></div><div><br></div>







<div><br></div></div>
</div></blockquote><blockquote type="cite"><div>&lt;NilInSwitchStatements.playground.zip&gt;</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>