All new in Apple’s Swift

Apple’s Swift programming language received a wide range of updates during WWDC 2022. Here’s a roundup of the best features coming to iOS 16 and macOS Ventura very soon.

Development of Swift began in 2010 by Chris Lattner and was introduced to the Apple developer community in 2014. In late December 2015, Apple released Swift and its libraries, package manager and debugger for public use as open source software source.

Since then, it has been accessible to the public and anyone wishing to contribute to the development can do so. And, Apple adds features and capabilities almost every year.

Following WWDC 2022, we picked the most significant features added to the language. Here are the details of what’s new in Swift and the complementary UI backend, SwiftUI.

What’s new in Swift 5.7

The core programming language, Swift, has received a number of surface-level quality-of-life updates.

These include castable types to designate data types to help manage application execution workflows, an optional binding to dynamically extract and process constant and variable value forms, and a checker to ensure maximum compatibility with a device’s available APIs.

Types of shipment

Now applications can be split into separate subsections and run concurrently. They can also send and receive data from each other.

Different sub-applications may contain data designated as irremovable because they involve or are part of an active system process that involves heavy overwriting that cannot be interrupted.

Sendable types allow developers to mark different specified data as “sendable” or “unsendable”, to improve application workflows.

Binding optional

The optional binding allows the application to check whether a value exists in a function and whether it is a constant or a variable.

This value can be extracted into another function, constant or variable, and use additional features, such as a live reading of such a value.

API availability check feature

As apps are deployed and installed on devices with many different software versions, the availability of application programming interfaces (APIs) varies from device to device. New in Swift 5.7 is the ability for an application to check if such an API is available on the device, and for the developer to define a fallback if the API is not available on the device.

This will allow apps to work better on more devices.

What’s new in SwiftUI

Many different updates are included in this year’s SwiftUI refresh, with Swift Charts headlining the new additions. Three branches of updates are present here: push-and-pop navigation stacks, detail-rich split views, and multi-window app experiences.

Navigation improvements include richer lists in devices like the Apple Watch. In a convoluted interface involving many different forms of toggles that mix switches and visual previews, SwiftUI now better presents options and aligns interface elements in a more appropriate visual style.

The API can populate a specific pre-designed interface for different types of data input, such as a number or a date. It also improved the support for data tables and its presentation. The updates also include new split views, which display the list alongside expanded body content, like the Settings app on iPad.

New, smaller pop-up report sheets for lists are also available. Inline text fields in apps can now expand to continue displaying the entire input.

SwiftUI also gained support for better adaptation of dark mode UI elements and better inline scaling of UI elements. Additionally, better UIKit interoperability with SwiftUI has been introduced.

There’s a new Share Sheet API, plus lots of improvements for macOS. The desktop operating system will receive better support for its floating and resizable windows. Finally, support for widgets on the lock screen has been added for the upcoming iOS 16.

Quick graphics

With Swift Charts, numbers and data imported into apps can take advantage of native-looking charts.

A new view in SwiftUI joining others such as Lists, Charts takes imported data and automatically generates charts. Line charts, bar charts, pie charts, and column charts are among the many different chart types now supported as part of SwiftUI. Swift Charts also supports six different types of marks, including the common line and point options, as well as the less common ruler option.

Built into Swift and using the same interface as Apple for their own applications, developers can customize the legend, color, scale, and opacity of chart elements. Swift Charts automatically manages localization, dark mode usage, and dynamic fonts.

System interface customization options are also available for graphics. Developers can set the background color, enable or disable the option to display individual data points, change highlighted data settings, and enable tabs to switch between different timescales.

Distributed actors in Swift

In multiplayer games, especially in a peer-to-peer environment, individual game data must be generated, received, and sent to and from different devices connected to the same network. Swift’s new Distributed Actor feature makes multiplayer games more viable.

In addition to native transparency features that allow debuggers to easily track errors by examining the activities of each connected device, bot support is also added. This will allow a game to insert computer players in addition to connecting players to other human opponents.

Distributed actors work with games using both a central server and peer-to-peer connections to serve gameplay across multiple devices.

The feature can also be applied in non-gaming contexts where data needed to be changed and synced and updated instantly across all devices on a network.

Swift Async Algorithms

In a fast data stream, such as a cloud photo album with multiple members, data arrives at unpredictable, clumped intervals that don’t quite match system refresh times. For the operator, he may need to oversee system hangs when the timing and amount of incoming data is difficult for the system to sustain.

To solve this problem, the new Swift feature that deals with asynchronous data imports called asynchronous algorithms is introduced. Asynchronous algorithms sort the data stream in real time and group it into tiny time intervals so that information can arrive at a server at predictable times.

Clock and Debounce allows the system to wake up the server only when new data arrives and schedule the next entry when the data stream is silent, respectively.

Asynchronous algorithms can also be used to join and separate data points for even more optimized data streams.

Quick regular expression

Regex, or regular expressions, channels the various forms of expression styles into standardized forms. For example, the layout of the month, day, and year may differ from region to region. Using regex will help systems get the correct date information in international workflows.

The Swift standard library now offers Regex as one of the types.

New in Swift 5.7 is the improved Regex engine, which is basically a search function that attempts to match exact text or data type to search queries. This is a useful feature for scanning large databases looking for data in a flexible way with more specific queries.

The ability to incorporate a Regex engine is now built into Swift. The engine parses and processes the data and sorts it into categories dictated by the code created by the developer. This includes text strings, as well as more general information such as date and time. The engine then discerns exactly what the data represents and standardizes it, so that it is not affected by region-specific modes of expression that can be confusing for users and developers in another region.

Search queries are also more precise and dynamic, and can be set to different match levels.

Read on AppleInsider

Harry L. Blanchard