Programming/Mac & iOS

[Swift] Swift 1.2 is come out!!

MB Brad KWON 2015. 2. 11. 10:58

New language features



  • as! for failable casts — Casts that can fail at runtime are now expressed with the new as!operator to make their potential for runtime failure clear to readers and maintainers of your code.
  • Nullability may now be expressed in Objective-C headers — New Objective-C extensions in Clang allow you to express the nullability of pointers and blocks in your Objective-C API. You can provide Objective-C frameworks that work great with Swift code, and improve your Swift experience when mixing and matching with Objective-C code in your own project.
  • Swift enums can now be exported to Objective-C using the @objc attribute — For example, the following Swift code:
@objc enum Bear: Int {
	case Black, Grizzly, Polar
}

imports into Objective-C as:

typedef NS_ENUM(NSInteger, Bear) {
	BearBlack, BearGrizzly, BearPolar
};
  • let constants are now more powerful and consistent — The new rule is that a let constant must be initialized before use (like a var), and that it may only be initialized, not reassigned or mutated after initialization.

This enables patterns like:

let x : SomeThing
if condition {
	x = foo()
} else {
	x = bar()
}
use(x)

This formerly required the use of a var even though there is no mutation taking place. Properties have been folded into this model to simplify their semantics in initializers as well.

  • More powerful optional unwrapping with if let — The if let construct can now unwrap multiple optionals at once, as well as include intervening boolean conditions. This lets you express conditional control flow without unnecessary nesting.
  • New native Set data structure — An unordered collection of unique elements that bridges with NSSet and provides value semantics like Array and Dictionary.

Conclusion

We appreciate all of the bugs you have filed, and expect that many of the most common issues have been fixed in this beta. Swift 1.2 is a major step forward for both the language and the tools. It does include some source-incompatible changes that require updates to your code, so Xcode 6.3 includes a migrator to help automate the process. To begin the migration, click the Edit menu, then choose Convert > To Swift 1.2...



출처 : https://developer.apple.com/swift/blog/?id=22