[swift-evolution] If-let Shortcut Syntax
Richard Fox
fox.ios.dev at gmail.com
Thu Dec 3 17:13:13 CST 2015
Hi all,
I propose a shortened syntax for using if-let with local names unwrapping
higher order optionals of the same name. i. e.
if let a {
//code
}
as a shortcut for this:
if let a = a{
//code
}
>From my observations echoing the local let variable name on the optional
being unwrapped seems to have become the commonly used practice.
I do not see this conflicting with any existing code.
My only thought's on potential pitfalls are if there is a local variable
and higher order variable both with the same name, as there may be
confusion as to which you are unwrapping. Although I don't see this as a
huge issue, as fault for such an error seems like it would weigh mostly on
architectural mistakes.
Also I think this would go hand in hand with a guard implementation of the
same nature
guard let a else{
//code
}
Thanks,
Rich Fox
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/ccca9b12/attachment.html>
More information about the swift-evolution
mailing list