[swift-evolution] Obsoleting `if let`
Brent Royal-Gordon
brent at architechies.com
Thu Feb 4 00:23:33 CST 2016
> The original proposal says
>
> if let name? = optionalCondition { }
>
> This would unwrap it?
>
> This seems like it should be mean the opposite.
The reason it unwraps it is that the thing on the left is a pattern, kind of like the cases of a case statement:
switch optionalCondition {
case let name?:
// optionalCondition was not nil; name here is non-optional
case nil:
// optionalCondition was nil
}
Think of it as the left side specifying a template the right side must match, with `let name` capturing the value corresponding to that particular position in the template.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list