[swift-evolution] Allow let binding of non-optionals
jtbandes at gmail.com
Thu Jan 7 13:08:46 CST 2016
I think you might have misunderstood Joe's suggestion — it does work for
me. Here's an example:
if let y = somethingOptional(),
case let x = somethingNonOptional()
where x != y
On Thu, Jan 7, 2016 at 11:07 AM, Gwendal Roué <gwendal.roue at gmail.com>
> 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> 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:
> // error
> if let x = value...
> // OK
> let x = value
> if …
> 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