<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=""> <font face="Andale Mono" class=""> 7> switch str {<br class=""> 8. case "foo": print("case foo")<br class=""> 9. case .none: print("(nil)")<br class=""> 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=""> ^<br class=""> !<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 <<a href="mailto:nevin.brackettrozinsky@gmail.com" class="">nevin.brackettrozinsky@gmail.com</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 <swift-evolution@swift.org> 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 UIKit<br class=""><br class=""><br class=""><br class="">var str:String? = "Hello, playground"<br class=""><br class=""><br class=""><br class="">switch str{<br class=""><br class="">case nil:<br class=""><br class=""> print("Nil!")<br class=""><br class="">case "Hello, playground": //it would be super nice if this worked.<br class=""><br class=""> print("Match")<br class=""><br class="">default:<br class=""><br class=""> 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 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 (case let s where s == "Hello, playground":), but that is verbose. <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=""><NilInSwitchStatements.playground.zip><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>