Swift Programming Language

31 thoughts
last posted Aug. 6, 2014, 9:41 p.m.

11 earlier thoughts

0

Ah, I now understand the if let thing better.

Optionals evaluate to a boolean so if foo is a String? then you can say if foo to test if foo is non-nil.

Now if foo is non-nil, you can say foo! to get that value (you'll get a runtime error if foo is nil).

So:

if let bar = foo {
    ...
}

is syntactic sugar for:

if foo {
    let bar = foo!
    ...
}

19 later thoughts