[swift-evolution] Proposal: Optional Binding Shorthand Syntax

Alex Lew alexl.mail+swift at gmail.com
Sun Dec 6 15:43:13 CST 2015


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/869babf6/attachment.html>


More information about the swift-evolution mailing list