<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="">&quot;Hello, playground&quot;</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="">    </span><span class="">print</span><span class="">(</span><span class="">&quot;Nil!&quot;</span><span class="">)</span></p>
<p class=""><font color="#ff9900"><span class="">case</span><span class=""> </span><span class="">&quot;Hello, playground&quot;</span><span class="">:  </span><span class="">//it would be super nice if this worked.</span></font></p>
<p class=""><span class="">    </span><span class="">print</span><span class="">(</span><span class="">&quot;Match&quot;</span><span class="">)</span></p>
<p class=""><span class="">default</span><span class="">:</span></p>
<p class=""><span class="">    </span><span class="">print</span><span class="">(</span><span class="">&quot;Some other non nil value?&quot;</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  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 class="">case</span><span class=""> </span><span class="">let</span><span class=""> s </span><span class="">where</span><span class=""> s == </span><span class="">&quot;Hello, playground&quot;</span><span class="">:</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>