<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="">On Dec 16, 2015, at 6:17 AM, Marco Masser via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><div><blockquote type="cite" class="">In Swift, an <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;"><</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;">></span> 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> array: [<span class="" style="color: rgb(112, 61, 170);">AnyObject</span>]? = <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=""> object </span><span class="" style="color: rgb(187, 44, 162);">in</span><span class="" style=""> </span><span class="" style="color: rgb(79, 129, 135);">array</span><span class="" style=""> { </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;"> …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></div></blockquote><div><br class=""></div><div>This topic has come up in internal discussions several times. We’ve discussed adding new features to for/in loop to handle it, having something like “in?” as you suggest:</div><div><br class=""></div><div><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> array: [<span class="" style="color: rgb(112, 61, 170);">AnyObject</span>]? = <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> object <span class="" style="color: rgb(187, 44, 162);">in?</span> array { <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;"> …</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. 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> object <span class="" style="color: rgb(187, 44, 162);">in</span> array ?? [] {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></div></blockquote><div><br class=""></div><div>Thus this isn’t really solving a big problem, and making the language more complex isn’t worth it.</div><div><br class=""></div><div>-Chris</div></div></body></html>