<div dir="ltr">How about:<div><br><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;anonymous pro&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> c: [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">]? = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">nil</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;anonymous pro&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">c</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">map</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">for</span><span style="font-variant-ligatures:no-common-ligatures"> e </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">in</span><span style="font-variant-ligatures:no-common-ligatures"> $0 { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures">(e) } }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;anonymous pro&#39;;color:rgb(0,143,0)"><span style="font-variant-ligatures:no-common-ligatures">// 1</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;anonymous pro&#39;;color:rgb(0,143,0)"><span style="font-variant-ligatures:no-common-ligatures">// 2</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;anonymous pro&#39;;color:rgb(0,143,0)"><span style="font-variant-ligatures:no-common-ligatures">// 3</span></p><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div><div><span style="font-variant-ligatures:no-common-ligatures">Based on <a href="https://developer.apple.com/reference/swift/optional/1539476-map#discussion">https://developer.apple.com/reference/swift/optional/1539476-map#discussion</a></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><div class="gmail_quote"><div dir="ltr">On Thu, Feb 9, 2017 at 11:26 PM Rick Mann via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is there any concise way to write the following?<br class="gmail_msg">
<br class="gmail_msg">
if let collection = someOptionalCollection<br class="gmail_msg">
{<br class="gmail_msg">
    for item in collection<br class="gmail_msg">
    {<br class="gmail_msg">
    }<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
I can imagine more complicated things, too:<br class="gmail_msg">
<br class="gmail_msg">
if let collection = someOptionalCollection as? [SomeType]<br class="gmail_msg">
{<br class="gmail_msg">
    for item in collection<br class="gmail_msg">
    {<br class="gmail_msg">
    }<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
It would be nice to be able to just attempt to iterate on an optional collection (or Sequence?) and not have to write the enclosing if block<br class="gmail_msg">
<br class="gmail_msg">
Thanks!<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Rick Mann<br class="gmail_msg">
<a href="mailto:rmann@latencyzero.com" class="gmail_msg" target="_blank">rmann@latencyzero.com</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-users mailing list<br class="gmail_msg">
<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
</blockquote></div></div></div></div>