<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 15 Aug 2016, at 22:08, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Mon, Aug 15, 2016 at 3:05 PM, Charles Srstka<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:cocoadev@charlessoft.com" target="_blank" class="">cocoadev@charlessoft.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><span class=""><blockquote type="cite" class="">On Aug 15, 2016, at 2:27 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""></blockquote><div class=""><blockquote type="cite" class=""><br class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">`let value = (x == nil) ? nil : foo.bar(x: x)` isn't so bad, is it? You could even write a custom operator to sugar it.</span></div></blockquote></div><br class=""></span><div class="">It’s distasteful, due to the need to use the force-unwrap operator. In cases like this, I usually end up writing:</div><div class=""><br class=""></div><div class="">let value: Foo? = nil</div><span class=""><div class=""><br class=""></div><div class="">if let x = x {</div></span><div class=""><span style="white-space: pre-wrap;" class="">        </span>value = foo.bar(x: x)</div><div class="">} else {</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>value = nil</div><div class="">}</div><div class=""><br class=""></div><div class="">or:</div><div class=""><br class=""></div><div class="">let value: Foo? = {</div><span class=""><div class=""><span style="white-space: pre-wrap;" class="">        </span>if let x = x {</div></span><div class=""><span style="white-space: pre-wrap;" class="">                </span>return foo.bar(x: x)</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>} else {</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>return nil</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>}</div><div class="">}()</div><div class=""><br class=""></div><div class="">Both of which are unwieldy, but necessary to avoid the use of !.</div></div></blockquote><div class=""><br class=""></div><div class="">You are arguing that the force unwrap operator ! is, per se, distasteful?</div></div></div></blockquote><div><br class=""></div><div>I wouldn't want ! all over my codebase, and I think the Swift language generally encourages that behaviour. In my opinion the use of ! is always caused by either a sloppy design or a language/compiler limitation. Directly comparing to nil is also something I try to avoid.</div><div><br class=""></div><div>Not everyone feels this strongly about force unwrapping as I do, probably. But to me, force unwrapping is not a worthy alternative to the proposed new sugar, and I’d rather write some boilerplate code.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><br class=""></div><div class="">I wouldn’t mind something like an overload on the ternary operator:</div><div class=""><br class=""></div><div class="">let value = x? ? foo.bar(x: x) : nil</div><div class=""><br class=""></div><div class="">in which a ? after the ternary condition indicates that it is an optional to be unwrapped for the positive condition.</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Charles</div></font></span></div></blockquote></div></div></blockquote></div><br class=""></body></html>