Does `case &quot;text&quot;?` work?<div><br><br>On Tuesday, June 28, 2016, Kevin Nattinger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Case .none:</div><div>Case .some(&quot;string&quot;):</div><div><br></div><div><br>On Jun 28, 2016, at 06:40, Lucas Jordan via swift-evolution &lt;<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;swift-evolution@swift.org&#39;);" target="_blank">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><span>import</span><span> UIKit</span></p>
<p><span></span><br></p>
<p><span>var</span><span> str:</span><span>String</span><span>? = </span><span>&quot;Hello, playground&quot;</span></p>
<p><span></span><br></p>
<p><span>switch</span><span> </span><span>str</span><span>{</span></p>
<p><span>case</span><span> </span><span>nil</span><span>:</span></p>
<p><span>    </span><span>print</span><span>(</span><span>&quot;Nil!&quot;</span><span>)</span></p>
<p><font color="#ff9900"><span>case</span><span> </span><span>&quot;Hello, playground&quot;</span><span>:  </span><span>//it would be super nice if this worked.</span></font></p>
<p><span>    </span><span>print</span><span>(</span><span>&quot;Match&quot;</span><span>)</span></p>
<p><span>default</span><span>:</span></p>
<p><span>    </span><span>print</span><span>(</span><span>&quot;Some other non nil value?&quot;</span><span>)</span></p>
<p><span>}</span></p></div><div><br></div><div><br></div><div>But it does not work, the orange  text is a compile time error, &quot;Expression pattern of type &#39;String&#39; cannot match value of type &#39;String?&#39;. I realize that this can be replaced with a let statement (<span>case</span><span> </span><span>let</span><span> s </span><span>where</span><span> s == </span><span>&quot;Hello, playground&quot;</span><span>:</span>), but that is verbose. </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="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;swift-evolution@swift.org&#39;);" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote></div>