<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">No<div class=""><br class=""></div><div class="">&nbsp;<font face="Andale Mono" class=""> 7&gt; switch str {<br class="">&nbsp; 8. case "foo": print("case foo")<br class="">&nbsp; 9. case .none: print("(nil)")<br class="">&nbsp;10. }<br class="">error: repl.swift:8:6: error: value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?<br class="">case "foo": print("case foo")<br class="">&nbsp; &nbsp; &nbsp;^<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !<br class=""></font>Odd error, but at least it suggests it’s an issue with optionaity.<br class=""><br class=""><blockquote type="cite" class="">On Jun 28, 2016, at 9:27 AM, Nevin Brackett-Rozinsky &lt;<a href="mailto:nevin.brackettrozinsky@gmail.com" class="">nevin.brackettrozinsky@gmail.com</a>&gt; wrote:<br class=""><br class="">Does `case "text"?` work?<br class=""><br class=""><br class="">On Tuesday, June 28, 2016, Kevin Nattinger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">Case .none:<br class="">Case .some("string"):<br class=""><br class=""><br class="">On Jun 28, 2016, at 06:40, Lucas Jordan via swift-evolution &lt;swift-evolution@swift.org&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Forgive me if this was/is discussed already, I am new to the process here....<br class=""><br class="">(code is attached as a playground too)<br class=""><br class=""><br class=""><br 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:<br class=""><br class="">import&nbsp;UIKit<br class=""><br class=""><br class=""><br class="">var&nbsp;str:String? =&nbsp;"Hello, playground"<br class=""><br class=""><br class=""><br class="">switch&nbsp;str{<br class=""><br class="">case&nbsp;nil:<br class=""><br class="">&nbsp; &nbsp;&nbsp;print("Nil!")<br class=""><br class="">case&nbsp;"Hello, playground": &nbsp;//it would be super nice if this worked.<br class=""><br class="">&nbsp; &nbsp;&nbsp;print("Match")<br class=""><br class="">default:<br class=""><br class="">&nbsp; &nbsp;&nbsp;print("Some other non nil value?")<br class=""><br class="">}<br class=""><br class=""><br class=""><br class="">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&nbsp;that this can be replaced with a let statement (case&nbsp;let&nbsp;s&nbsp;where&nbsp;s ==&nbsp;"Hello, playground":), but that is verbose.&nbsp;<br class=""><br class="">Seems like the compiler could be OK with the orange text, since it is clearly not nil.<br class=""><br class="">Thoughts?<br class=""><br class="">-Lucas<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""></blockquote><blockquote type="cite" class="">&lt;NilInSwitchStatements.playground.zip&gt;<br class=""></blockquote><blockquote type="cite" class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote></blockquote><br class=""></div></body></html>