<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 10, 2016, at 4:33 AM, Sam Dods 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I propose that <font face="Menlo" class=""><b class="">(case .Foo = bar)</b></font> should be treated as an expression with a Boolean value, so the result can be set to a variable or returned from a method.</div></div></div></blockquote><div><br class=""></div><div>I agree that this is an important use case that Swift doesn’t serve well right now, but I don’t think this is the right way to go. </div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Considering the following enumeration:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><b class="">enum Bar {</b></font></div><div class=""><font face="Menlo" class=""><b class=""> case foo(name: String)</b></font></div><div class=""><font face="Menlo" class=""><b class=""> case notFoo</b></font></div><div class=""><font face="Menlo" class=""><b class=""> case unknownFoo</b></font></div><div class=""><font face="Menlo" class=""><b class="">}</b></font></div></div></div></blockquote><div><br class=""></div><div>One of the things we’ve discussed in the past is that we could have enums automatically “synthesize” instance members for projecting cases as optional values or bools. For example, the above enum could be compiled into the equivalent of:</div><div><br class=""></div><div>extension Bar {</div><div> func getAsFoo() -> String? { … }</div><div> var isNotFoo : Bool { … }</div><div> var isUnknownFoo : Bool { … }</div><div>}</div><div><br class=""></div><div>Then you could just use:</div><div><br class=""></div><div> if someBar.isUnknownFoo { … }</div><div> if someBar.isFoo != nil { … }</div><div> if let name = someBar. getAsFoo() {... }</div><div> someBar. getAsFoo()?.doThing() </div><div><br class=""></div><div>etc. There is a question of naming, and getting the details right, of course.</div><div><br class=""></div><div>-Chris</div></div></body></html>