Affiliate Disclosure
If you buy through our links, we may get a commission. Read our ethics policy.

Everything new in Apple's Swift

Apple's programming language Swift got a wide array of updates at WWDC 2022. Here's a roundup of the best features that are coming alongside iOS 16 and macOS Ventura very soon.

Swift development started 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.

Since then, it has been publicly available and anyone who wishes to contribute to the development may do so. And, Apple adds features and capabilities nearly every year.

Following the 2022 WWDC, we chose 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 main programming language, Swift, received a number of surface-level quality-of-life updates.

These include Sendable Types to denote data types to assist with dealing with app runtime workflows, Optional Binding to extract and dynamically deal with both constant and variable forms of values, and a checker to ensure maximum compatibility with a device's available APIs.

Sendable Types

Now, apps can be divided into distinct sub-sections and be run concurrently. They can also send and receive data from one another.

Different sub-apps might have data that are designated as immovable because it involves or is part of an active system process that involves extensive overwriting that cannot be disrupted.

Sendable Types allow developers to tag different specified data as "sendable" or "unsendable," to improve app workflows.

Optional Binding

Optional Binding allows the app to check if a value exists within a function and if it's a constant or variable.

That value can be extracted into another function, constant or variable, and use additional functionality, such as a live readout of such a value.

API Availability Checking Functionality

As apps are deployed and installed on devices with many differing software versions, application programming interfaces (APIs) vary in availability from device to device. New in Swift 5.7 is the ability for an app to check if such an API is available on the device, and for the developer to set a fallback should the API be unavailable on the device.

It will allow apps to function 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 complicated interface involving lots of different forms of toggles that mix switches and visual previews, SwiftUI now better presents the options, and aligns interface elements in a more proper visual style.

The API can populate specific pre-designed interface for different data input types, such as a number or date. It also has improved support for data tables and its presentation. The updates also include new split views, which shows the list alongside the 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 showing the full input.

SwiftUI also gained support for better adaptation of UI elements in Dark Mode, and better in-line scaling of interface elements. In addition, better UIKit interoperability with SwiftUI was introduced.

There's a new Share Sheet API, as well as numerous improvements for macOS. The desktop operating system will receive better support for its floating and resizable windows. Finally, Widgets on the Lock Screen support was added for the upcoming iOS 16.

Swift Charts

With Swift Charts, figures 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 graphs, bar charts, pie charts, and histograms are among the many different chart types now supported as part of SwiftUI. Swift Charts also supports six different mark types including the common line and point options, as well as the less common rule option.

Integrated into Swift and utilizing the same interface as Apple does for their own apps, developers can customize the legend, color, scale, and opacity to chart elements. Swift Charts automatically handles localization, the use of Dark Mode, and dynamic fonts.

System interface customization options are also available for Charts. Developers can set the background color, enable or disable the option to view individual data points, change highlighted data parameters, 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 needs to be generated, received, and sent to and from different devices connected to the same network. The new Distributed Actor function in Swift makes multiplayer games more viable.

In addition to native transparency features that allow debuggers to easily track for errors by peering into the activities of every 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 both using a central server and peer-to-peer connections to serve gameplay across multiple devices.

The function can also be applied in non-game contexts where data needed to be edited and synchronized and be instantaneously updated across all devices in a network.

Swift Async Algorithms

In a fast-moving data stream, such as a cloud photo album with multiple members, data arrives at unpredictable and clustered intervals that don't quite line up with system refresh times. For the operator, they might have to oversee system hangs when the timing and the amount of data coming in is hard for the system to bear.

To solve this, the new Swift feature that deals with asynchronous data imports called Async Algorithms is introduced. Async Algorithms sort through the data stream in real-time, and clusters them into tiny set time intervals so information can arrive at a server at predictable times.

Clock and Debounce allows the system to wake the server only when new data is arriving, and schedule the next input for when the data stream is quiet, respectively.

Async Algorithms can also be used to join and break apart data points for even more optimized data flows.

Swift Regex

Regex, or Regular Expressions, funnel the various forms of expression styles into standardized forms. For example, the arrangement of the month, day, and year might differ from region to region. The use of regex will help systems obtain the correct date information across international workflows.

The Swift Standard Library now features Regex as one of the types.

New in Swift 5.7 is the improved Regex Engine, which is essentially a search feature that attempts to match the precise text or data type to search queries. This is a feature that is useful to scan large databases for data in flexible ways with more specific queries.

The ability to incorporate a Regex Engine is now built-in inside of Swift. The engine parses and processes the data, and sorts them into the categories dictated by the developer-created code. This includes strings of text, as well as more general information like date and time. The engine then discerns exactly what the data represents, and standardizes them, so they are unaffected by region-specific ways of expression that may be confusing to users and developers of another region.

Search queries are also more granular and dynamic, and can be set to varying levels of matching.



1 Comment

FileMakerFeller 6 Years · 1561 comments

Thanks very much for this summary.

For me, Swift (and especially SwiftUI) has the same smell as Project Pink from the 1990s. I hope I'm wrong. But for all of the hype and the momentum and rapid evolution taking place, it looks like it's really difficult to build good quality apps with the new stack. That will, eventually, kill the technology.

Again, I hope I'm wrong. It could be that what we're seeing right now is an inability of experienced developers to adapt to the new paradigm, which is an endemic problem with all sorts of technology, and the next few years will see enough youngsters coming in to get over the hump. But after 8 years in mainstream production, I don't know that the current issues can correctly be called teething problems.