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.
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:
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:
- SE-0143 Conditional Conformance
- SE-0157 Support recursive constraints on associated types
- SE-0185 Synthesizing Equatable and Hashable conformance
- SE-0187 Introduce Sequence.compactMap(_:)
- SE-0188 Make Standard Library Index Types Hashable
- SE-0191 Eliminate IndexDistance from Collection
For more information about progress made with conditional conformance in Swift 4.1, check out this blog post.
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
See more at: SE-0075 Adding a Build Configuration Import Test and Conditional Compilation Block documentation.
Target environment condition
targetEnvironment(simulator) platform condition returns
true when code is compiled for a simulator; otherwise, it returns
See more at: SE-0190 Target environment platform condition and Conditional Compilation Block documentation.
JSONDecoder classes now support new strategies for converting keys during encoding and decoding.
This was discussed in more detail in this forum post.
These are additional Swift Evolution proposals that were implemented in this release:
- SE-0184 Unsafe[Mutable][Raw][Buffer]Pointer: add missing methods, adjust existing labels for clarity, and remove deallocation size
- SE-0186 Remove ownership keyword support in protocols
- SE-0189 Restrict Cross-module Struct Initializers
- SE-0198 Playground QuickLook API Revamp
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:
- Use word-size field in native object header for reference counting (SR-4353)
- Review the efficiency of interacting with the enum discriminator through the witness table (SR-4332)
- Decide the layout of existential type metadata, including protocol descriptors (SR-4341)
- Define canonicalization of generic and protocol requirements for order-agnostic mangling (SR-3733)
- Audit of every runtime function for desirability and behavior (SR-3735)
- Enforce appropriate constraints on
- Collapse various collection wrappers using conditional conformance (SR-3458)
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
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.
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.
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
For development on Apple’s platforms, Swift 4.1 ships as part of Xcode 9.3.
Development on Swift 4.1 was tracked in the swift-4.1-branch on the following repositories on GitHub:
swift-4.1-RELEASE designates the specific revisions in those repositories that make up the final version of Swift 4.1.
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.