[swift-evolution] Auto Unwrapping Of Optionals

Tyler Cloutier cloutiertyler at aol.com
Mon May 2 18:38:12 CDT 2016


The difference between the if-let syntax and the below syntax is that the type of foo never changes with the if-let syntax. Instead a new variable is created which shadows the original foo. The distinction is important because types don’t implicitly change in Swift. The implicit change is called "type narrowing”, that this has been discussed previously here: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005475.html

I can definitely see the argument for no implicit type changes, but I can also see the argument that the syntax is much nicer.

Tyler


> On Apr 30, 2016, at 10:11 PM, David Sweeris via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Apr 29, 2016, at 1:23 PM, Haravikk via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> This is definitely something I’m hoping to see as well, alongside more intelligent handling of the is keyword, as currently Swift doesn’t handle the following either:
>> 
>> 	if foo is SomeType { /* foo could be safely used as SomeType here, but currently is not */ }
>> 
>> Hopefully someone more familiar can weigh in, as it seems like something I expect to be on the way but perhaps has been delayed in case any further changes to the type system were required?
> 
> This can be handled with the if-let syntax:
> if let foo = foo as? SomeType { … }
> although I think your idea is more readable.
> 
> - Dave Sweeris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160502/04e1f208/attachment.html>


More information about the swift-evolution mailing list