Swift 4.2 Released! September 17, 2018 Ted Kremenek is a member of the Swift Core Team and manages the Languages and Runtimes group at Apple.

Swift 4.2 is now officially released! Swift 4.2 builds on the strengths of Swift 4, delivering faster compile times, improving the debugging experience, updating the standard library, and converging on binary compatibility.

You can watch a quick overview of it by watching the WWDC 2018: What’s New in Swift presentation, and try out some of the new features in this playground put together by Ole Begemann.

Swift 4.2 is a major language release and contains the following language changes and updates that went through the Swift Evolution process:

Generics improvements

With the completion of conditional conformance support, Swift 4.2 makes significant progress in implementing the vision of generics in the language. Better support for generics ultimately reduces the amount of boilerplate needed in your code and make more of your code reusable. To learn more about conditional conformance, see more at:

Watch the Swift Generics WWDC 2018 presentation for more details.

The standard library in Swift 4.2 includes a number of new features, including improvements to the Hashable protocol as well as a new unified set of randomization functions and protocols.

See more at:

Binary compatibility

Swift 4.2 brings the language closer towards a stabilized ABI, enabling binary compatibility for future releases of Swift. Visit the ABI Dashboard for more details on the current progress of this effort.

Swift 4.2 includes a number of improvements that have a noticable impact on developer experience, including:

Support for batch mode compilation resulting in faster build times

Change in calling convention for retain/release cycle to reduce code size and improve runtime performance

Lazier SIL deserialization with -Onone

Recursive metadata support

More compact reflection metadata

Default arguments are inlined at call sites

Some long-standing bug fixes, including init declname, switch with multiple case labels per block, inheritance of generic initializers, and more

Swift 4.2 also implements the following language proposals from the Swift Evolution process:

Swift 4.2 introduces new features for the Swift Package Manager:

Support for batch mode. Swift targets will be now compiled using the Swift compiler’s batch mode.

Automatic Xcode project generation. The generate-xcodeproj has a new –watch option to watch the file system and automatically regenerate the Xcode project if needed. This uses the watchman tool to watch the required files.

Improved scheme generation logic. The scheme generation logic is improved and generates schemes as follows: One scheme containing all regular and test targets of the root package. One scheme per executable target containing the test targets whose dependencies intersect with the dependencies of the executable target.



Swift 4.2 also implements the following Package Manager proposals from the Swift Evolution process:

SE-0201 Package Manager Local Dependencies. SwiftPM now supports declaring dependency on a package using its path on disk instead of the git URL. This requires updating the package’s tools version to 4.2.

SE-0208 Package Manager System Library Targets. The PackageDescription API in tools version 4.2 supports a new type of target “system library target”, which moves the current system-module packages feature from package to target level.

SE-0209 Package Manager Swift Language Version API Update. swiftLanguageVersions property in PackageDescription manifest API for tools version 4.2 is changed from an array of Integers to an array of SwiftVersion enum.

Migrating to Swift 4.2

Swift 4.2 is source compatible with Swift 4, Swift 4.1 and Swift 3. Swift 4.2 will be the last release to provide source compatibility with Swift 3.

To help with moving to Swift 4.2 from earlier releases of Swift, Apple’s Xcode 10 contains a code migrator that can automatically handle many of the needed source changes. There is also a migration guide available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.

Documentation

An updated version of The Swift Programming Language for Swift 4.2 is now available on Swift.org. It is also available for free on the Apple Books store.

Platforms

Linux

Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are available for download.

Apple (Xcode)

For development on Apple’s platforms, Swift 4.2 ships as part of Xcode 10.

A toolchain is also available for download from Swift.org.

Sources

Development on Swift 4.2 was tracked in the swift-4.2-branch on the following repositories on GitHub:

The tag swift-4.2-RELEASE designates the specific revisions in those repositories that make up the final version of Swift 4.2.