Skip to content
SwiftMind
swiftmedium impactReleased 2023-09-18

Swift 5.9 — macros and ownership

Macros arrive as a first-class language feature, and the ownership model gains noncopyable types.

new

Macros

Compile-time code generation with full type information. This is the mechanism behind @Observable and much of SwiftData, so understanding what a macro expands to is now part of reading ordinary framework code.

new

Noncopyable types (~Copyable)

A type can declare that it must not be copied, giving the compiler enough information to enforce unique ownership of a resource. Relevant when a value represents something that genuinely cannot be duplicated, such as a file handle or a lock.

new

if and switch as expressions

Both can now produce a value directly, which removes a great deal of var x: T followed by assignment in every branch.

Affects