<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 Dec 16, 2015, at 10:51 AM, Chris Lattner 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Dec 16, 2015, at 6:17 AM, Marco Masser via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><div class=""><blockquote type="cite" class="">In Swift, an&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Optional</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span>&nbsp;can’t be used this way:<br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;array: [<span class="" style="color: rgb(112, 61, 170);">AnyObject</span>]? =&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="color: rgb(187, 44, 162);">for</span><span class="" style="">&nbsp;object&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span><span class="" style="">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">array</span><span class="" style="">&nbsp;{&nbsp;</span>// Compiler error: Value of optional type '[AnyObject]?' not unwrapped; did you mean to use '!' or '?'?</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">This topic has come up in internal discussions several times. &nbsp;We’ve discussed adding new features to for/in loop to handle it, having something like “in?” as you suggest:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;array: [<span class="" style="color: rgb(112, 61, 170);">AnyObject</span>]? =&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">for</span>&nbsp;object&nbsp;<span class="" style="color: rgb(187, 44, 162);">in?</span>&nbsp;array {&nbsp;<span class="" style="color: rgb(0, 132, 0);">// Note the “in?”</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">etc. &nbsp;However, the discussion kept coming back to the fact that we have a pretty trivial way to express this already:</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div></div></div></div></div><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="">I know this is a very minor thing and it can be worked around easily by code like this:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">for</span>&nbsp;object&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;array ?? [] {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Thus this isn’t really solving a big problem, and making the language more complex isn’t worth it.</div></div></div></div></blockquote><div><br class=""></div>FWIW, the above only works when "array" is an array or set. &nbsp;In a generic context you might not even know how to construct an empty one.</div><div><br class=""></div><div>a?.forEach { object in ... }</div><div><br class=""></div><div>is the generic version I think.</div><div><br class=""></div><div><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=""><div class=""><br class=""></div><div class="">-Chris</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2iYqF2IN28N3PtpDvYnkSK4g9Mrf1UdTAex8TruxT1b1GtZ0ihYWo6eT2ZdHnIGDYEBOkEXnHy9hHXt9Vjn3vNSOD7GnjVe-2FsNLczH5lz5Dgt-2Fa2hGpw0Wz-2FW54t30-2FUEwP1sVaf4ORbc61MlM42JccJkYHPJR-2B1-2F1cKlxB10z7n0WSDfxeDjEfT0TjF7COMmQ-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</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=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>