Swift 4.1 Released!

Ted KremenekTed Kremenek

Swift 4.1 is now officially released! It contains updates to the core language, including more support for generics, new build options, as well as minor enhancements to Swift Package Manager and Foundation. There was also significant progress made in stabilizing the ABI.

Doug Gregor and Ben Cohen recently discussed many of these features on a two-part episode of the Swift Unwrapped podcast. Check out the podcasts here:Part 1 andPart 2.

Compiler Updates

Swift 4.1 is a minor language release. It is source compatible with Swift 4.0. It contains the following language changes and updates, most of which went through the SwiftEvolution process:

Language improvements

Swift 4.1 adds more generics features to the language, furthering the goals set out in theSwift Generics Manifesto. The following generics-related proposals have been implemented in this release:

For more information about progress made with conditional conformance in Swift 4.1, check out thisblog post.

Build improvements

This release provides more ways to configure your builds, including a new code size optimization and easier ways to specify target environment and platform support.

Code size optimization mode

The compiler now supports a new optimization mode which enables dedicated optimizations to reduce code size.

This was previously discussed in more detail in thisblog post.

Build import test

The argument for thecanImport() platform condition is the name of a module that may not be present on all platforms. This condition tests whether it’s possible to import the module, but doesn’t actually import it. If the module is present, the platform condition returnstrue; otherwise, it returnsfalse.

See more at:SE-0075 Adding a Build Configuration Import Test and Conditional Compilation Blockdocumentation.

Target environment condition

ThetargetEnvironment(simulator) platform condition returnstrue when code is compiled for a simulator; otherwise, it returnsfalse.

See more at:SE-0190 Target environment platform condition and Conditional Compilation Blockdocumentation.

Foundation

TheJSONEncoder andJSONDecoder classes now support new strategies for converting keys during encoding and decoding.

This was discussed in more detail in thisforum post.

Additional updates

These are additional Swift Evolution proposals that were implemented in this release:

ABI Stability

Swift 4.1 contains a number of under-the-hood changes that are part of the effort to stabilize the ABI in Swift 5. Here is list of the tasks that were completed in this release:

For more information about the progress of ABI Stability for Swift, check out theABI Dashboard.

Package Manager Enhancements

There are a couple of enhancements to Swift Package Manager in Swift 4.1:

Swift Package Manager now correctly resolves dependences in package graphs that use different URL schemes, such asssh andhttp.Performance has been significantly improved for package graphs that have shared dependencies.

Migrating to Swift 4.1

Swift 4.1 is source compatible with Swift 4.0. To help with moving to Swift 4.1 from earlier releases of Swift, Apple’sXcode 9.3 contains a code migrator that can automatically handle many of the needed source changes. There is also amigration 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 ofThe Swift Programming Language for Swift 4.1 is now available on Swift.org. It is also available for free on Apple’s iBooks store.

Platforms

Linux (Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10)

Official binaries for Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10 areavailable for download

Apple (Xcode)

For development on Apple’s platforms, Swift 4.1 ships as part ofXcode 9.3.

Sources

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

The tagswift-4.1-RELEASE designates the specific revisions in those repositories that make up the final version of Swift 4.1.

Theswift-4.1-branch will remain open, but under the samerelease management process, to accumulate changes for a potential future bug-fix “dot” release.