Swift 5.2 adds language changes and clearer error messages

Share
  • March 27, 2020

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.

SEE ALSO: COVID-19 vs open source: How developers are fighting the virus

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.

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.

SEE ALSO: Progressive React Apps

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.

Source : JAXenter