Swift 4.1 Released!

Ted Kremenek is a member of the Swift Core Team and manages the Languages and Runtimes group at Apple.

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 and Part 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 Swift Evolution process:

Language improvements

Swift 4.1 adds more generics features to the language, furthering the goals set out in the Swift 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 this blog 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 this blog post.

Build import test

The argument for the canImport() 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 returns true; otherwise, it returns false.

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

Target environment condition

The targetEnvironment(simulator) platform condition returns true when code is compiled for a simulator; otherwise, it returns false.

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

Foundation

The JSONEncoder and JSONDecoder classes now support new strategies for converting keys during encoding and decoding.

This was discussed in more detail in this forum 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 the ABI 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 as ssh and http. 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’s Xcode 9.3 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.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 are available for download

Apple (Xcode)

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

Sources

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

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

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