Swift 4.2 Released!
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:
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.
Standard Library updates
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:
- SE-0197 Adding in-place removeAll(where:) to the Standard Library
- SE-0199 Adding toggle to Bool
- SE-0202 Random Unification
- SE-0204 Add last(where:) and lastIndex(where:) Methods
- SE-0206 Hashable Enhancements
- SE-0207 Add an allSatisfy algorithm to Sequence
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.
Additional language and compiler updates
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:
- SE-0054 Abolish ImplicitlyUnwrappedOptional type. Read even more details about the reimplementation here.
- SE-0079 Allow using optional binding to upgrade self from a weak to strong reference
- SE-0193 Cross-module inlining and specialization
- SE-0194 Derived Collection of Enum Cases
- SE-0195 Introduce User-defined “Dynamic Member Lookup” Types
- SE-0196 Compiler Diagnostic Directives
- SE-0205 withUnsafePointer(to:_:) and withUnsafeBytes(of:_:) for immutable values
- SE-0210 Add an offset(of:) method to MemoryLayout
- SE-0212 Compiler Version Directive
Package Manager Updates
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.
swiftLanguageVersionsproperty 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.
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.
Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are available for download.
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.
Development on Swift 4.2 was tracked in the swift-4.2-branch on the following repositories on GitHub:
swift-4.2-RELEASE designates the specific revisions in those repositories that make up the final version of Swift 4.2.
swift-4.2-branch will remain open, but under the same release management process, to accumulate changes for a potential future bug-fix “dot” release.