Apple has debuted Swift 5.5, a “massive” release that fixes its “pyramid of doom” issue among introducing other major changes.
An issue with how Swift previously handled concurrency meant that a “pyramid of doom” of difficult-to-follow nested calls would occur when a developer wrote several asynchronous operations.
Swift language inventor Chris Lattner had previously acknowledged that error handling gets ugly “because Swift’s natural error handling mechanism cannot be used”. In a post, he provided an example of how code ends up looking:
‘Actors’ have also been introduced that allow you to “declare that a bag of state is held within a concurrency domain and then define multiple operations that act upon it.” The data of each actor is protected through data isolation to ensure only a single thread will access it at any given time.
As part of the new concurrency model, “actors provide the same race and memory safety properties as structured concurrency, but provide the familiar abstraction and reuse features that other explicitly declared types in Swift enjoy.”
The additions and changes in Swift 5.5 can justifiably be called “massive”. Here are the proposals that were included in the latest version:
- SE-0291 Package Collections
- SE-0293 Extend Property Wrappers to Function and Closure Parameters
- SE-0295 Codable synthesis for enums with associated values
- SE-0296 Async/await
- SE-0297 Concurrency Interoperability with Objective-C
- SE-0298 Async/Await: Sequences
- SE-0299 Extending Static Member Lookup in Generic Contexts
- SE-0300 Continuations for interfacing async tasks with synchronous code
- SE-0304 Structured concurrency
- SE-0306 Actors
- SE-0307 Allow interchangeable use of CGFloat and Double types
- SE-0308 if for postfix member expressions
- SE-0310 Effectful Read-only Properties
- SE-0311 Task Local Values
- SE-0313 Improved control over actor isolation
- SE-0314 AsyncStream and AsyncThrowingStream
- SE-0316 Global actors
- SE-0317 async let bindings
- SE-0319 Conform Never to Identifiable
Another headline feature that’s worth digging into a little bit more is package collections.
A package contains Swift source code files and a manifest. As the name suggests, a package collection gathers several together for convenience. “We envision educators and community influencers publishing package collections to go along with course materials or blog posts, removing the friction of using packages for the first time and the cognitive overload of deciding which packages are useful for a particular task,” states the original proposal.
Swift 5.5 is now available in Xcode 13 or it can be grabbed for Ubuntu, CentOS, Amazon Linux 2, or Windows 10.
Head this way for the downloads.
Want to learn about DevOps from leaders in the space? Check out the DevOps-as-a-Service Summit on 1 February 2022, where attendees will learn about the benefits of building collaboration and partnerships in delivery.