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 
> <[email protected]> wrote:
> 
> 
>> On Apr 29, 2016, at 1:23 PM, Haravikk via swift-evolution 
>> <[email protected] <mailto:[email protected]>> 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
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to