Swift 5 Released with ABI Stability, Reducing App Size Across Platforms

Swift 5, as expected, has been released ahead of WWDC 2019.

Calling it a “major milestone in the evolution of the language,” Swift leader Ted Kremenek writes that the Swift runtime is now included across Apple’s family of operating systems: macOS, iOS, tvOS, and watchOS. With ABI stability (which had been expected to arrive with Swift 5), all Swift libraries will be incorporated into operating system releases. This will allow app file size to shrink, as developers won’t need to include those libraries.

Here are other updated features now included in the standard library:

  • 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.

String literals are also changed, mostly because developers are lazy (no, really, we are). String literals in Swift 5 now support raw text, meaning anything can be included in a String Literal, including copy-pasted code. Escaped code is an issue; code copied and pasted from other files is often not escaped manually, which can crash code or make debugging difficult. From the Swift Evolution GitHub repo, proposal SE-200:

Importantly, raw strings are transportable. They allow developers to cut and paste content both from and to the literal string. This allows testing, reconfiguration, and adaption of raw content without the hurdles escaping and unescaping that limit development.

Strings have been updated to UTF-8 encoding, which is a memory, performance, and efficiency move. It also improves server-side and client-side communication, as well as C interoperability.

With Swift 5 comes Xcode 10.2, which has some nifty new features, as well. If your updated apps include the Swift runtime, App Store thins it automatically so apps and games download faster to iOS devices. Playgrounds has “various stability improvements and additional memory safety checks.”

(If you need some living examples of these changes, there’s a downloadable Xcode Playground via GitHub. It hasn’t been updated since Swift 5 was officially released, but it’s a much cleaner way to see these things in action than trying to parse the various Swift Evolution pages.)

We’d previously called ABI stability the “last corner” Swift had to turn. That remains true, at least for Xcode and Apple platforms. There are still LSP and server-side considerations, which will help Swift gain ubiquity across platforms. One small feature in Swift 5 that will also help is dynamic “callable” types, which Kremenek says will “help improve interoperability with dynamic languages such as Python, JavaScript and Ruby.”