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 From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Download all Swift 5.7 changes as a playground Link to Swift 5.7 changes
Link copied to your pasteboard.