Michael Long
Apr 9, 2022

--

The shadow var is an edge case.

`if let thisIsALongName { }`

Is the primary use. And in most cases you still need to do some assignment when unwrapping optional chains.

`let date = myStruct?.date?.formatted().`

This will also be nice for.

`guard let self else { return }`

`if let self { ... }`

All in all, I think it's a handy bit of syntactic sugar, and I said as much in Swift Evolution. Glad to see it finally got added to the language.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet