[swift-users] for with optional collection?

Rick Mann rmann at latencyzero.com
Thu Feb 9 15:26:54 CST 2017


Is there any concise way to write the following?

if let collection = someOptionalCollection
{
    for item in collection
    {
    }
}

I can imagine more complicated things, too:

if let collection = someOptionalCollection as? [SomeType]
{
    for item in collection
    {
    }
}

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

Thanks!

-- 
Rick Mann
rmann at latencyzero.com




More information about the swift-users mailing list