What’s new in Swift 5

Share
  • March 26, 2019

There were a lot of new services announced at Apple’s press event at its California HQ, including the launch of Apple Card, a paid-for News+ service and a new premium TV offering, to name a few. Find out more about the announcements here.

However, these services were not the only things Apple unveiled. Ted Kremenek, manager of the languages and runtimes team at Apple, announced the release of Swift 5, which represents a major milestone in the evolution of this language.

Swift 5 highlights

As Kremenek noted in the blog post, “thanks to ABI stability, the Swift runtime is now included in current and future versions of Apple’s platform operating systems: macOS, iOS, tvOS, and watchOS. Swift 5 also introduces new capabilities that are building blocks for future versions, including a reimplementation of String, enforcement of exclusive access to memory during runtime, new data types, and support for dynamically callable types.”

If you’d like to give some of the features a try, check out this playground created by Paul Hudson.

Language updates

As mentioned above, the ABI is now stable for Swift 5 on Apple platforms, which means the Swift libraries are incorporated into every macOS, iOS, tvOS, and watchOS release going forward. In short, thanks to ABI stability, users will be able to build apps easier; plus, they will also be smaller since there’s no reason to include those libraries.

There are a bunch of new features in the standard library in Swift 5, such as

  • String reimplemented with UTF-8 encoding which can often result in faster code
  • Improved support for raw text in string literals
  • Result and SIMD vector types added to the Standard Library
  • Enhancements to String interpolation, adding more flexibility to construct text from data
  • Performance improvements to Dictionary and Set

The latest release implements the following Standard Library proposals from the Swift Evolution process

Furthermore, Swift 5 defaults to enforcing exclusive access to memory for both debug and release builds. It also supports dynamically callable types that help improve interoperability with dynamic languages such as Python, JavaScript and Ruby.

The following language proposals from the Swift Evolution process are implemented in Swift 5

Package manager updates

There are a bunch of new features in Swift Package Manager, such as dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data, to name a few.

Swift Package Manager includes a number of new features in Swift 5, including dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data. What’s more, the swift run command now includes the ability to import libraries in a REPL without needing to build an executable.

Swift 5 implements three Package Manager proposals from the Swift Evolution process, namely

Migration

The latest version is source compatible with Swift 4, Swift 4.1 and Swift 4.2. To make things easier, Apple’s Xcode 10.2 contains a code migrator that can automatically handle many of the needed source changes. There’s also a migration guide available to guide you through many of the changes.

Last but not least, you’ll find the updated version of The Swift Programming Language for Swift 5 on Swift.org, as well as on the Apple Books store (for free!).

The post What’s new in Swift 5 appeared first on JAXenter.

Source : JAXenter