WWDC 2022: What's new in Swift
Find hereafter a detailed summary of the aforementioned video which belongs to a taxonomy of some WWDC footages.
The original video is available on the official Apple website (session 110354).
"Join us for an update on Swift. 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."
The outlines of this speech are indicated hereunder:
Most of the illustrations are parts of the Apple presentations and may be available at the Resources
section inside the Overview
sheet of each video.
Hereafter, the underlined elements lead directly to the playback of the WWDC video at the appropriate moment.
Community updates #
Two new workgroups are added in the open source model for Swift.
The mentorship program goes on its way for one more year and keeps on counting on volunteers to become more efficient.
New points of interest have been added to this mentorship whose connection may be done on the Swift blog.
Regarding the distribution of Swift through the Redhat Packet Manager, a significant assistance is provided for Linux package formats.
Some huge enhancements have been made for harnessing Swift as a server solution.
Swift packages #
TOFU #
This acronym stands for a new security protocol that handles the package signature when it's first downloaded.
Command plugins #
Swift can be used for automation instead of authoring script shells.
Creating a plug-in relies on using Swift by defining a struct that conforms to the CommandPlugin protocol and that holds the orders to be executed through the Swift Package Manager
command line interface.
Module disambiguation #
Module disambiguation is the solution provided by Swift 5.7 to avoid the module collisions through the use of the moduleAliases keyword.
Performance improvements #
The Swift Driver that coordinates the compilation of Swift source code in Swift is now completely combined with the Xcode build system to streamline and significantly speed up the builds.
Huge enhancements have been made regarding the type-checker performances...
... and the protocol conformance checking that uses cache to improve the runtime process.
Concurrency updates #
iOS 13 and macOS Catalina have now the ability to use the concurrency model introduced in iOS 15 by holding a copy of the Swift 5.5 concurrency runtime for older OS versions in the app.
Enhancements have been supplied, in part for the compiler in the build settings, with the view to achieving the Swift 6 objective in the concurrency model area.
Introduced last year, actors are making a significant progress in Swift 5.7 with the new distributed actors that can be put on different machines with a network between them in order to make the developing distributed systems much simpler.
The Instruments
tool offers a new Swift Concurrency view including statistics and a graphical representation of the parent-child relationships between tasks in structured concurrent code referred to as a Task Forest.
Expressive Swift #
The new way to unwrap an optional with the if let
expression is also compatible with the guard let
one.
A closure's result type isn't necessary to be explicitly defined whatever the complicated way it's been authored.
A complete equivalence between C and Swift regarding the pointer conversions is now possible through a separate set of rules for calls to imported functions and methods in Swift.
Regex literals #
The brand-new RegexBuilder library in Swift 5.7 permits to describe a pattern in a string in a more readable way than the traditional regex syntax.
Note that the usual regex literals can still be used in the middle of a regex builder.
Generics & Protocols #
The use of the any
keyword when dealing with protocols makes things clearer and refines the potential related error messages.
The primary associated types feature permits to specify the types in parameter without using the where
clause.
Even if many enhancements have been introduced in Swift 5.7 regarding the any
keyword in addition to the replacement of a type-erasing wrapper by a built-in language feature, there are still use cases where it's definitely not appropriate to use it concerning both the capabilities and the performance areas.