<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I nevertheless think that this is a bug and should be addressed. There is no reason where<div class=""><br class=""></div><div class="">if stringOptional == stringNonOptional { ... }</div><div class=""><br class=""></div><div class="">works, but pretty much the same construct doesn't work in the switch-case. It should be perhaps solved via a bugreport at <a href="http://bugs.swift.org" class="">http://bugs.swift.org</a> and via evolution, though...<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 29, 2016, at 12:31 AM, Nevin Brackett-Rozinsky via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="font-size:12.8px" class="">I just got home and tested. The answer is yes, `case "text"?` does work.</span><div style="font-size:12.8px" class=""><font face="monospace, monospace" class=""><br class=""></font></div><div style="font-size:12.8px" class=""><div class=""><font face="monospace, monospace" class="">let optStr : String? = "text"</font></div><div class=""><font face="monospace, monospace" class="">switch optStr {</font></div><div class=""><font face="monospace, monospace" class="">case nil : print("Nil")</font></div><div class=""><font face="monospace, monospace" class="">case "text"? : print("Success")</font></div><div class=""><font face="monospace, monospace" class="">default : print("Default")</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class="">// Prints `</font><span style="font-family:monospace,monospace" class="">Success`</span></div></div><div class="" style="font-size:12.8px"><div id=":2zn" class="" tabindex="0"><img class="" src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif" style=""></div></div><span class="" style="font-size:12.8px"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Nevin</div></font></span><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jun 28, 2016 at 12:27 PM, Nevin Brackett-Rozinsky <span dir="ltr" class=""><<a href="mailto:nevin.brackettrozinsky@gmail.com" target="_blank" class="">nevin.brackettrozinsky@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Does `case "text"?` work?<div class="HOEnZb"><div class="h5"><div class=""><br class=""><br class="">On Tuesday, June 28, 2016, Kevin Nattinger via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><div class="">Case .none:</div><div class="">Case .some("string"):</div><div class=""><br class=""></div><div class=""><br class="">On Jun 28, 2016, at 06:40, Lucas Jordan via swift-evolution <<a class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">Forgive me if this was/is discussed already, I am new to the process here....<div class=""><br class=""></div><div class="">(code is attached as a playground too)</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><p class=""><span class="">import</span><span class=""> UIKit</span></p><p class=""><span class=""></span><br class=""></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 class=""></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="">"Nil!"</span><span class="">)</span></p><p class=""><font color="#ff9900" class=""><span class="">case</span><span class=""> </span><span class="">"Hello, playground"</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="">"Match"</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="">"Some other non nil value?"</span><span class="">)</span></p><p class=""><span class="">}</span></p></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">But it does not work, the orange 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. </div><div class=""><br class=""></div><div class="">Seems like the compiler could be OK with the orange text, since it is clearly not nil.</div><div class=""><br class=""></div><div class="">Thoughts?</div><div class=""><br class=""></div><div class="">-Lucas</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>
<div class=""><br class=""></div></div>
</div></blockquote><blockquote type="cite" class=""><div class=""><NilInSwitchStatements.playground.zip></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></blockquote></div>
</div></div></blockquote></div><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>