You should test it out — I'd guess there's a good chance it gets optimized out.<br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 28, 2016 at 2:58 PM Rick Mann <<a href="mailto:rmann@latencyzero.com">rmann@latencyzero.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yeah, I suppose that works. Feels a bit clunky, like the language lacks specific support for this (in that it provides specific support for so many other common constructs). But I guess I can make do with that.<br>
<br>
I suppose there's a bit of a performance hit, in that constructing an empty array and iterating over it is more expensive than a simple nil check, but that's unlikely to cause issues in practice.<br>
<br>
Thanks.<br>
<br>
> On Jul 28, 2016, at 14:56 , Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>> wrote:<br>
><br>
> How about "for item in someOptionalContainer ?? []" ?<br>
><br>
> On Thu, Jul 28, 2016 at 2:55 PM, Rick Mann via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:<br>
> I often call methods that return an optional collection. I then iterate over it. The problem is, it's a bit cumbersome to write:<br>
><br>
> if let container = someOptionalContainer<br>
> {<br>
> for item in container<br>
> {<br>
> }<br>
> }<br>
><br>
> I wish I could just write<br>
><br>
> for item in someOptionalContainer<br>
> {<br>
> }<br>
><br>
> such that if the optional is nil, it just skips the iteration altogether.<br>
><br>
> Is there a syntax for that (especially in Swift 3)?<br>
><br>
><br>
> --<br>
> Rick Mann<br>
> <a href="mailto:rmann@latencyzero.com" target="_blank">rmann@latencyzero.com</a><br>
><br>
><br>
> _______________________________________________<br>
> swift-users mailing list<br>
> <a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
><br>
<br>
<br>
--<br>
Rick Mann<br>
<a href="mailto:rmann@latencyzero.com" target="_blank">rmann@latencyzero.com</a><br>
<br>
<br>
</blockquote></div>