[swift-evolution] Allow let binding of non-optionals
gwendal.roue at gmail.com
Thu Jan 7 13:07:41 CST 2016
> Le 7 janv. 2016 à 20:02, Joe Groff <jgroff at apple.com> a écrit :
>> On Jan 7, 2016, at 10:59 AM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> do let value2 = somethingNonOptional()
> 'case let' already works like this, by declaring a pattern 'let a' that unconditionally matches anything.
Well, the compiler complains, and does not provide any nice suggestion.
I, and most code I’ve seen so far (including StackOverflow), solve this issue with an extra variable declared in the outer scope:
if let x = value...
let x = value
Remember the double role of `if let`: 1. unwrap the optional, 2. define a new variable, scoped to the `if` statement. We have 1, but not 2, and this is the gist of this thread.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution