<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=""><div class="">What I often do is use ?? to provide a default (usually false).</div><div class=""><br class=""></div><div class="">if myList?.isEmpty ?? false {</div><div class="">&nbsp; &nbsp; print(“Empty”)</div><div class="">} else {</div><div class="">&nbsp; &nbsp; print(“Not empty”)</div><div class="">}</div><div class=""><br class=""></div><div class="">The other thing you can do, of course, is to use a ‘where’ statement:</div><div class=""><br class=""></div><div class="">if let list = myList where list.isEmpty {</div><div class="">&nbsp; &nbsp; print(“Empty”)</div><div class="">} else {</div><div class="">&nbsp; &nbsp; print(“Not empty”)</div><div class="">}</div><div class=""><br class=""></div><div class="">Charles</div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 31, 2016, at 4: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><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello,<div class=""><br class=""></div><div class="">This is a Idea I got from&nbsp;Objetive-C, where nil is evaluate no false, this feature can keep the code clean.&nbsp;For example:</div><div class=""><br class=""></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-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">if (![myList isEmpty]) { ... }</pre></div><div class=""><div class="">Will&nbsp;evaluate&nbsp;true or false even if myList is nil.</div></div><div class="">I know that Swift is not Design to work like Objetive-C, but sometimes this make the code cleaner. &nbsp;</div><div class=""><br class=""></div><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-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">if !myList?.isEmpty { print("Ok") }</pre><p class="p1">This is much more cleaner and easy to read than:<br class=""></p><pre class="prettyprinted prettyprint notranslate" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;padding:5px;margin-top:0px;margin-bottom:10px;border-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">if !(myList != nill &amp;&amp; mylist!.isEmpty) { print("Ok") }</pre><p class="p1">Moreover the tip from the Xcode (when you type the &nbsp;lead user to generate wrong code when you type this code :</p><pre class="prettyprinted prettyprint notranslate" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;padding:5px;margin-top:0px;margin-bottom:10px;border-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">if !((myList?.isEmpty)) != nil { print("Ok") }</pre><p class="p1">As you can see the suggestion made by the Xcode will not work, because event if the list is empty the expression will return true.</p><p class="p1">My ideia is to use some special syntax that permit optional to be evaluate to boolean expression. Those syntax may be <a href="http://www.tutorialspoint.com/ruby/ruby_if_else.htm" class="">like in ruby</a>.&nbsp;</p><div class=""><span class="s2"></span><br class="webkit-block-placeholder"></div><pre class="prettyprinted prettyprint notranslate" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace;padding:5px;margin-top:0px;margin-bottom:10px;border-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)"><span class="pln" style="box-sizing: border-box;">code </span><span class="kwd" style="color:rgb(0,0,136)">if</span><span class="pln" style="box-sizing: border-box;"> condition</span></pre><div class="">So the code from the example will be:</div><div class=""><br class=""></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-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">print ("Ok") if !myList?.isEmpty</pre></div><div class="">Or using the unless keyword:</div><div class=""><br class=""></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-radius:0px;width:604px;line-height:16px;border:1px solid rgb(214,214,214);font-size:12px;overflow:auto;color:rgb(49,49,49);background-color:rgb(238,238,238)">unless myList?.isEmpty print("not empty") else print "empty"</pre></div><div class=""><br class=""></div></div><div class="">I didn't spent much time thinking about the syntax keyword, because I want to know first if you will consider a great addition to the language, if so, we can work on details and a formal proposal.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>