Swift 1.2 is out! Well, sorta-out — it’s bundled with the latest Xcode beta, and I’m still a little hesitant to jump on the beta Xcode train having been burnt one time too many. Plus, I’m not sure I like the idea of having my dev tools be ‘beta’, especially in the oh-wow-it-really-is-beta way that Apple uses the term.
If you want a highlight of changes in 1.2, jump over to NSHipster — but the most exciting change for me is a slight syntactic sugar around optional binding that turns the let-pyramid of doom:
1
2
3
4
5
6
7
8
9
10
11
|
var foo:String? = “foo”
var bar:String? = “bar”
var baz:String? = “baz”
if let foo = foo {
if let bar = bar {
if let baz = baz {
// Do something with foo, bar, and baz
}
}
}
|
into a sensible, manageable one-liner:
1
2
3
4
5
6
7
|
var foo:String? = “foo”
var bar:String? = “bar”
var baz:String? = “baz”
if let foo = foo, bar = bar, baz = baz {
// Do something with foo, bar, and baz
}
|
Leave a Reply