Swift 5.2 has been released. The general-purpose programming language, developed by Apple, was introduced in a keynote in 2014: “The language is called Swift and it totally rules.”
A year later, the language was open sourced. With its focus on speed, Swift should serve as a replacement for C, C++ and Objective-C. Let’s dive right in and see what’s new in v5.2.
Features in Swift 5.2
Swift 5.2 implements two language proposals. Both are additive changes, which means they have no impact on API resistance, source compatibility or ABI stability.
The first proposal, SE-0249, means Swift users can now use the key path expression Root.value
wherever (Root) -> Value
functions are allowed. SE-0253 introduces “statically” callable values to Swift. This can, for example, be useful for values that represent mathematical functions or function expressions.
by Manfred Steyer (SOFTWAREarchitekt.at)
by Andrey Goncharov (Hazelcast)
In the latest version, Swift users should also notice some developer experience improvements. The compiler diagnostics—errors and warnings—should now show more information.
For example, this code tries to compare an enum
value with a case that doesn’t exist:
enum E { case one, two }
func check(e: E) {
if e != .three {
print("okay")
}
}
The error message in Swift 5.1 isn’t clear about where the problem lies:
error: binary operator '!=' cannot be applied to operands of type 'E' and '_'
if e != .three {
~ ^ ~~~~~~
Swift 5.2, on the other hand, tells you exactly what went wrong:
error: type 'E' has no member 'three'
if e != .three {
~^~~~~
Another aspect of the compiler diagnostics has also received an upgrade: Unnecessary type checking has been removed, which should increase the speed of code completion.
Further updates in Swift 5.2 refer to debugging, the handling of dependencies in the Swift Package Manager, LSP and SwiftSyntax.
Swift 5.2 is available for Apple platforms, where it ships with the macOS IDE Xcode in version 11.4, and for Linux.
See the release notes for more information.
The post Swift 5.2 adds language changes and clearer error messages appeared first on JAXenter.