Swift 5.7 Announced
We’ll take you through performance improvements, explore more secure and extensible Swift packages, and share advancements in Swift concurrency. We’ll also introduce you to Swift Regex, better generics, and other tools built into the language to help you write more flexible & expressive code.
Generics are a fundamental tool for writing abstract code in Swift. Learn how you can identify opportunities for abstraction as your code evolves, evaluate strategies for writing one piece of code with many behaviors, and discover language features in Swift 5.7 that can help you make generic code easier to write and understand.
Design protocol interfaces in Swift:
Learn how you can use Swift 5.7 to design advanced abstractions using protocols. We’ll show you how to use existential types, explore how you can separate implementation from interface with opaque result types, and share the same-type requirements that can help you identify and guarantee relationships between concrete types
Meet distributed actors in Swift:
Discover distributed actors — an extension of Swift’s actor model that simplifies development of distributed systems. We’ll explore how distributed actor isolation and location transparency can help you avoid the accidental complexity of networking, serialization, and other transport concerns when working with distributed apps and systems.
Visualize and optimize Swift concurrency:
Learn how you can optimize your app with the Swift Concurrency template in Instruments. We’ll discuss common performance issues and show you how to use Instruments to find and resolve these problems. Learn how you can keep your UI responsive, maximize parallel performance, and analyze Swift concurrency activity within your app.
Eliminate data races using Swift Concurrency:
Join us as we explore one of the core concepts in Swift concurrency: isolation of tasks and actors. We’ll take you through Swift’s approach to eliminating data races and its effect on app architecture. We’ll also discuss the importance of atomicity in your code, share the nuances of
Sendable
checking to maintain isolation, and revisit assumptions about ordering work in a concurrent system.
Discover the latest open source Swift package from Apple: Swift Async Algorithms. We’ll explore algorithms from this package that you can use with
AsyncSequence
, includingzip
,merge
, andthrottle
. Follow along with us as we use these algorithms to build a great messaging app. We’ll also share best practices for combining multipleAsyncSequences
and using the SwiftClock
type to work with values over time.
• • •
Xcode 14 ships with Swift 5.7, which brings massive improvements to generics and protocols! 🧵
Swift 5.7 introduces a new, more concise way to unwrap optional values using
if let
andguard let
statements.
While it sounds like the
any
keyword acts as a type erasing helper, all it really does is inform the compiler that you opt-in to using an existential (a box type that conforms to a protocol) as your type.
In Swift 5.7, protocols can specify primary associated types. These associated types are a lot like generics. They allow developers to specify the type for a given associated type as a generic constraint.
Thankfully, this is a problem that Swift 5.7 neatly solves by expanding the
some
keyword (that was introduced back in Swift 5.1) to also be applicable to function arguments.[…]
Swift 5.7 once again introduces a much more lightweight way to express the above kind of declaration, which works the exact same way as when specializing a concrete generic type (such as
Array<Article>
). That is, we now can simply tell the compiler whatElement
type that we’d like our inputCollection
to contain by adding that type within angle brackets right after the protocol name[…]
“Any UIKit subclass that uses
deinit
now essentially causes warnings in Swift 5.7 while they are never touched on other threads anyways.”
(
Set
now uses the new Temporary Buffers feature to make operations likeintersect
up to 4-6x faster.
Previously:
- SwiftUI Changes at WWDC 2022
- Swift Regex
- Swift Charts
- Xcode 14 Announced
- Swift 5.6 Released
- Fixing Swift’s “if let” Syntax
- Swift 5 Preview
Update (2022-07-06): Matthaus Woolard and Natalia Panferova:
This post highlights some of the Swift updates that caught our attention this WWDC.