[swift-users] Compact iteration of optional collection?

Rick Mann rmann at latencyzero.com
Thu Jul 28 16:55:23 CDT 2016


I often call methods that return an optional collection. I then iterate over it. The problem is, it's a bit cumbersome to write:

     if let container = someOptionalContainer
    {
        for item in container
        {
        }
    }

I wish I could just write 

    for item in someOptionalContainer
    {
    }

such that if the optional is nil, it just skips the iteration altogether.

Is there a syntax for that (especially in Swift 3)?


-- 
Rick Mann
rmann at latencyzero.com




More information about the swift-users mailing list