Xcode Playground Lets Developers Try New Swift 5 Features

Apple yesterday announced Swift 5, which it describes as a major milestone release of the increasingly popular open source programming language used for iOS and other Apple operating systems.

To help mobile and other developers try out the new features of the release, developer Paul Hudson created an Xcode playground on GitHub in a project called "What’s new in Swift 5.0?"

"Swift 5.0 is the next major release of Swift, and brings ABI stability at long last," Hudson said in a like-titled companion blog post. "That's not all, though: several key new features are already implemented, including raw strings, future enum cases, a Result type, checking for integer multiples and more."

The Xcode playground provides a quick way to try those features out, specifically listing:

  • Raw strings
  • A standard Result type
  • Customizing string interpolation
  • Dynamically callable types
  • Handling future enum cases
  • Flattening nested optionals resulting from try?
  • Checking for integer multiples
  • Transforming and unwrapping dictionary values with compactMapValues()
Swift 5 Xcode Playground
[Click on image for larger view.] Swift 5 Xcode Playground (source: Paul Hudson)

Apple also echoed Hudson's take on that aforementioned ABI stability, with ABI standing for Application Binary Interface. "The ABI is now declared stable for Swift 5 on Apple platforms," Apple said in a blog post. "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."

In a post explaining more about ABI stability, Apple said: "ABI stability has been a goal for Swift since its inception, and brings with it many benefits for developers and users of these platforms:

  • Most obviously, applications written in Swift no longer need to be distributed with the Swift runtime libraries, reducing download size.
  • The Swift runtime can be more deeply integrated and optimized with these host operating systems, allowing Swift programs to launch faster, get better runtime performance, and use less memory.
  • Apple will be able to deliver platform frameworks using Swift in future OSes.
  • When a future version of Swift also provides module stability, third parties will also be able to ship binary frameworks written in Swift.

While Hudson's Xcode playground helps developers try out the new features listed above, new standard library features in Swift 5 highlighted by Apple include:

  • 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

Apple said Swift 5's new capabilities "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."

Introduced in June 2014, Swift has become increasingly popular, boosted by Apple taking it open source about a year later. Last October, Swift cracked the top 10 of the TIOBE index of programming language popularity.

Swift development is done in the open on GitHub.

About the Author

David Ramel is an editor and writer for Converge360.