Swift 4.0 Released! September 19, 2017 Ted Kremenek is a member of the Swift Core Team and manages the Languages and Runtimes group at Apple.

Swift 4 is now officially released! Swift 4 builds on the strengths of Swift 3, delivering greater robustness and stability, providing source code compatibility with Swift 3, making improvements to the standard library, and adding features like archival and serialization.

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

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

String

Swift 4 includes a faster, easier to use String implementation that retains Unicode correctness and adds support for creating, using and managing substrings.

See more at:

Collection

Swift 4 adds improvements for creating, using and managing Collection types.

See more at:

Archival and serialization

Swift 4 supports archival of struct and enum types and enables type-safe serialization to external formats such as JSON and plist.

See more at: SE-0166 Swift Archival & Serialization

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

New compatibility modes

With Swift 4, you may not need to modify your code to use the new version of the compiler. The compiler supports two language modes:

Swift 3.2: In this mode, the compiler will accept the majority of sources that built with the Swift 3.x compilers. Updates to previously existing APIs (either those that are part of the standard library or APIs shipped by Apple) will not appear in this mode, in order to provide this level of source compatibility. Most new language features in Swift 4 are available in this language mode.

Swift 4.0: This mode includes all Swift 4.0 language and API changes. Some source migration will be needed for many projects, although the number of source changes are quite modest compared to many previous major changes between Swift releases.

The language mode is specified to the compiler by the -swift-version flag, which is automatically handled by the Swift Package Manager and Xcode.

One advantage of these language modes is that you can start using the new Swift 4 compiler and migrate fully to Swift 4 at your own pace, taking advantage of new Swift 4 features, one module at a time.

For more information about Swift 4 migration and compatibility modes, see Migrating to Swift 4

Swift 4 introduces new workflow features and a more complete API for the Swift Package Manager:

It’s now easier to develop multiple packages in tandem before tagging your first official release, or to work on a branch of multiple packages together.

Package products have been formalized, making it possible to control what libraries a package publishes to clients.

The new Package API allows packages to specify a number of new settings, giving package authors more control over how packages build or how sources are organized on disk. Overall, the API used to create a package is now cleaner and clearer, while retaining source-compatibility with older packages.

On macOS, Swift package builds now occur in a sandbox which prevents network access and file system modification, to help mitigate the effect of maliciously crafted manifests.

Further, the Swift Package Manager builds on top of package manager tools versioning introduced in Swift 3.1 (SE-0159) which allows a package author to specify the version of Swift required for building a package — which now includes Swift 4.

For more information about enhancements to the Package Manager, see:

Documentation

An updated version of The Swift Programming Language for Swift 4.0 is now available on Swift.org. It is also available for free on Apple’s iBooks store.

Platforms

Linux

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

Apple (Xcode)

For development on Apple’s platforms, Swift 4.0 ships as part of Xcode 9.

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

Sources

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

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