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!
...
}