Here’s a practical list of Swift Evolution proposals implemented in Swift 6.0 (the initial 6.0 release), each with a tiny demo you can paste into a Swift 6 project. I pulled the proposal statuses directly from the Swift Evolution repo to keep this tight and accurate.
SE‑0415: Function body macros — generate function bodies at compile time. (GitHub)
@freestanding(expression)
macro time<T>(_ body: () -> T) -> T = #externalMacro(module: "MyMacros", type: "TimeMacro")
func work() -> Int {
#time { (1...1_000_000).reduce(0, +) }
}
SE‑0422: Expression macro as caller‑side default argument — let a macro provide a default at the call site. (GitHub)
@freestanding(expression) macro contextID() -> String = #externalMacro(module:"Macros", type:"ContextID")
func log(_ message: String, id: String = #contextID()) { print("[\(id)] \(message)") }
log("Started") // id is generated by the macro at call site
SE‑0416: Subtyping for key‑path literals as functions — key‑path literals coerce to compatible function types more flexibly. (GitHub)
struct User { var name: String; var age: Int }
let users = [User(name:"A", age:30), User(name:"B", age:20)]
let names: [String] = users.map(\.name) // key-path as function
let ages: [Int] = users.map(\.age) // now subtypes correctly
SE‑0405: String validating initializers — failable initializers that validate code points, etc. (GitHub)
if let s = String(validating: [0x61, 0x62, 0x63]) { // “abc”
print(s)
}
SE‑0421: Generalize AsyncSequence — AsyncSequence
can properly throw
from makeAsyncIterator()
and next()
. (GitHub)
struct Lines: AsyncSequence {
struct Iterator: AsyncIteratorProtocol {
mutating func next() async throws -> String? { /* may throw */ nil }
}
func makeAsyncIterator() -> Iterator { .init() } // throwing next()
}
SE‑0418: Inferring Sendable
for methods and key‑path literals — fewer manual annotations; safer defaults. (GitHub)
struct Worker {
func doIt(_ f: @escaping () -> Void) { Task { f() } } // closure can infer Sendable where needed
}
SE‑0423: Dynamic actor isolation — opt APIs into runtime‑checked isolation (useful for UI frameworks / plugins). (GitHub)
actor Counter { var value = 0 }
@dynamicActorIsolation
func bump(_ c: Counter) async { await c.value += 1 } // isolation verified dynamically
SE‑0434: Usability of global‑actor‑isolated types — smoother use of types isolated to a global actor like @MainActor
. (GitHub)
@MainActor
struct UIState { var text = "" }
let state = UIState()
await MainActor.run { print(state.text) } // fewer friction points with global-actor types
SE‑0437: Noncopyable standard library primitives — foundational building blocks for move‑only patterns. (GitHub)
SE‑0432: Borrowing/consuming pattern matching for noncopyable types — switch/let‑binding respect ownership. (GitHub)
noncopyable struct Token { let id: Int }
func use(_ t: borrowing Token) {}
func consume(_ t: consuming Token) {}
func handle(_ t: consuming Token) {
switch t { // can consume/borrow in patterns
// …
}
}
SE‑0426: BitwiseCopyable
— marker protocol to allow trivial copies by bit‑blit where safe. (GitHub)
struct POD: BitwiseCopyable { var x: Int, y: Int } // compiler can memcpy this safely
SE‑0429: Partial consumption for noncopyable types — consume parts of a value without consuming the whole. (GitHub)
noncopyable struct Pair { var a: Int; var b: Int }
func foo(_ p: consuming Pair) { let a = consume p.a /* … keep using p.b … */ }
SE‑0408: Pack iteration (variadic generics) — loop over parameter packs directly. (GitHub)
func zipPack<each S: Sequence>(_ s: repeat each S) {
for (repeat each element) in repeat (each s) { /* … */ }
}
SE‑0428: Resolve distributed‐actor protocols — better protocol interactions for distributed actors. (GitHub)
distributed actor Node: Sendable {
distributed func ping() async -> String { "pong" }
}
SE‑0410: Atomics — standard library atomics module. (GitHub)
import Atomics
let counter = ManagedAtomic(0)
counter.wrappingIncrement(ordering: .relaxed)
SE‑0270: RangeSet
& collection operations — merged in Swift 6 toolchains. (GitHub)
var set = RangeSet(0..<3)
set.insert(contentsOf: [10..<12, 20..<21])
print(set.contains(10)) // true