Swift 5 is now officially released!

Swift 5 is a major milestone in the evolution of the language. Thanks to ABI stability, the Swift runtime is now included in current and future versions of Apple’s platform operating systems: macOS, iOS, tvOS and watchOS. Swift 5 also introduces new capabilities that are building blocks for future versions, including a reimplementation of String, enforcement of exclusive access to memory during runtime, new data types, and support for dynamically callable types.

You can try out some of the new features in this playground put together by Paul Hudson.

Language Updates

Stable ABI and Binary Compatibility

The ABI is now declared stable for Swift 5 on Apple platforms. As a result, the Swift libraries are now incorporated into every macOS, iOS, tvOS, and watchOS release going forward. Your apps will be easier to build and smaller because they won’t have to include those libraries.

See these blog posts for more details:

  • ABI Stability and More
  • Evolving Swift On Apple Platforms After ABI Stability

Standard Library Updates

The standard library in Swift 5 includes the following new features:

  • String reimplemented with UTF-8 encoding which can often result in faster code (See the UTF-8 String blog post for more background on this change)
  • Improved support for raw text in string literals (See the String Literals blog post for more background on this refinement)
  • Result and SIMD vector types added to the Standard Library
  • Enhancements to String interpolation, adding more flexibility to construct text from data
  • Performance improvements to Dictionary and Set

Swift 5 implements the following Standard Library proposals from the Swift Evolution process:

  • SE-0200 Enhancing String Literals Delimiters to Support Raw Text
  • SE-0211 Add Unicode Properties to Unicode.Scalar
  • SE-0214 Renaming the DictionaryLiteral type to KeyValuePairs
  • SE-0215 Conform Never to Equatable and Hashable
  • SE-0218 Introduce compactMapValues to Dictionary
  • SE-0221 Character Properties
  • SE-0225 Adding isMultiple to BinaryInteger
  • SE-0228 Fix ExpressibleByStringInterpolation
  • SE-0229 SIMD Vectors
  • SE-0232 Remove Some Customization Points from the Standard Library’s Collection Hierarchy
  • SE-0233 Make Numeric Refine a new AdditiveArithmetic Protocol
  • SE-0234 Remove Sequence.SubSequence
  • SE-0235 Add Result to the Standard Library
  • SE-0237 Introduce withContiguous{Mutable}StorageIfAvailable methods
  • SE-0239 Add Codable conformance to Range types
  • SE-0241 Deprecate String Index Encoded Offsets

Additional Language and Compiler Updates

Swift 5 defaults to enforcing exclusive access to memory for both debug and release builds (See the Swift 5 Exclusivity Enforcement blog post for more information about this update). And Swift 5 supports dynamically callable types that help improve interoperability with dynamic languages such as Python, JavaScript and Ruby.

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

  • SE-0192 Handling Future Enum Cases
  • SE-0213 Literal initialization via coercion
  • SE-0216 Introduce user-defined dynamically “callable” types
  • SE-0224 Support ‘less than’ operator in compilation conditions
  • SE-0227 Identity key path
  • Se-0230 Flatten optionals resulting from ‘try? ‘

Package Manager Updates

Swift Package Manager includes a number of new features in Swift 5, including dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data. Additionally, the swift run command now includes the ability to import libraries in a REPL without needing to build an executable.

Swift 5 implements the following Package Manager proposals from the Swift Evolution process:

  • SE-0219 Package Manager Dependency Mirroring
  • SE-0236 Package Manager Platform Deployment Settings
  • SE-0238 Package Manager Target Specific Build Settings

Migrating to Swift 5

Swift 5 is source compatible with Swift 4, Swift 4.1 and Swift 4.2.

To help with moving to Swift 5 from earlier releases of Swift, Apple’s Xcode 10.2 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 5 is now available on Swift.org. It is also available for free on the Apple Books store.

Platforms

Linux

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

Apple (Xcode)

For development on Apple’s platforms, Swift 5 ships as part of Xcode 10.2.

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

Sources

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

  • swift
  • swift-clang
  • swift-clang-tools-extra
  • swift-cmark
  • swift-corelibs-foundation
  • swift-corelibs-libdispatch
  • swift-corelibs-xctest
  • swift-libcxx
  • swift-llbuild
  • swift-lldb
  • swift-llvm
  • swift-package-manager
  • swift-stress-tester
  • swift-syntax
  • swift-xcode-playground-support
  • swift-compiler-rt
  • swift-integration-tests

Revisions in The Tag Swift-5.0-release designates The specific Repositories that make up The final version of repositories Swift 5.

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