<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 style="font-size: 16px;" class=""><div style="font-size: 16px;"><blockquote type="cite" class=""><div class="">On Mar 31, 2016, at 3:54 PM, Guilherme Torres Castro via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div dir="ltr" class=""></div></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">Example:</div><div class=""><pre class="prettyprinted prettyprint notranslate" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 5px; margin-top: 0px; margin-bottom: 10px; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; width: 604px; line-height: 16px; border: 1px solid rgb(214, 214, 214); overflow: auto; color: rgb(49, 49, 49); background-color: rgb(238, 238, 238);">if !myList?.isEmpty { print("Ok") }</pre></div></div></div></blockquote><div><br class=""></div><div>Swift originally had Optionals be boolean evaluable. Unfortunately, nil does not always mean false, and assuming so by default can mask issues. I believe there may have also been an issue with types being promoted to optional and then evaluated as true.</div><div><br class=""></div>One option here is to use a new custom prefix operator to indicate you desire optional == false behavior. I chose “??” in the code below:</div><div style="font-size: 16px;"><br class=""></div><div style="font-size: 16px;"><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117); font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">prefix</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">operator</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ?? {}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">prefix</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ??(arg:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">?) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117); font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> arg ?? </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> data:[</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">?] = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13" class="">"nil"</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13" class="">"true"</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">true</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13" class="">"false"</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">false</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (key, value) </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">data</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #294c50" class="">??</span><span style="font-variant-ligatures: no-common-ligatures" class="">value {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(key)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; font-size: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">} # prints true</span></div><div style="margin: 0px; font-size: 17px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">I don’t think a negated form is as clear, since this is a shortcut for two checks. However, I wrote one for completeness:</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; font-size: 22px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">prefix</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">operator</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ‽‽ {}</span></div><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">prefix</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ‽‽(arg:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">?) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> !(arg ?? </span><span style="font-variant-ligatures: no-common-ligatures;" class="">false</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 15px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">-DW</span></div></div></span></div></div></body></html>