SE-0343 upgrades Swift’s support for top-level code – think main.swift in a macOS Command Line Tool project – so that it supports concurrency out of the box. This is one of those changes that might seem trivial on the surface, but took a lot of work to make happen.
In practice, it means you can write code like this directly into your main.swift files:
import Foundation let url = URL(string: "https://hws.dev/readings.json")! let (data, _) = try await URLSession.shared.data(from: url) let readings = try JSONDecoder().decode([Double].self, from: data) print("Found \(readings.count) temperature readings")
Previously, we had to create a new
@main struct that had an asynchronous
main() method, so this new, simpler approach is a big improvement.
SPONSORED An iOS conference hosted in Buenos Aires, Argentina – join us for the third edition from November 29th to December 1st!
Link copied to your pasteboard.