[swift-evolution] Proposal: Optional Binding Shorthand Syntax

Tyler Mandry tmandry at gmail.com
Sun Dec 6 15:46:58 CST 2015


Ah no, it's just that they at one time had support for taking away `case`
and doing `if let b? = a`. See the commit notes that Chris linked to here:
https://github.com/apple/swift/commit/20f8f09ea8de5eb1c0cb559e59c8a8e8a0e115a9#diff-4513b692cdd5476630ebb66b73d5bf4b
.

I guess the current `if let b = a` syntax is what John was referring to as
special syntactic support, but I still don't see why the `?` was taken out
of the syntax.

On Sun, Dec 6, 2015 at 3:43 PM, Alex Lew <alexl.mail+swift at gmail.com> wrote:

> let a: Int? = 3
> if case let b? = a {
>     print(b)
> }
>
> works for me in Swift 2.2. Have they announced that they're taking this
> away?
>
>
> On Sun, Dec 6, 2015 at 4:38 PM, Tyler Mandry via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> What isn't clear to me from Chris's or John's comments is why the `if let
>> x? = foo` syntax was taken away. Was it for backward-compatibility? To me,
>> this syntax does have special syntactic support, and also seems to make it
>> clearer what's going on. It's also analogous to Swift's type inference for
>> generic <T?> types, for example:
>>
>>    func doSomething<T? where T: Equatable>(x: T?) -> T { ... }
>>
>> Note the T? in brackets. If I pass an Int? to doSomething, the type is
>> "unwrapped" and T becomes Int. It seems like `if let x? = foo` would follow
>> the same pattern.
>>
>> Was the syntax taken away for reasons unlikely to change, or is it up for
>> discussion? :)
>>
>> --
>> Tyler Mandry
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>>
>


-- 
Tyler Mandry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/3b56af76/attachment.html>


More information about the swift-evolution mailing list