Getting the most from Swift Macros
summary
Shows how Swift 5.9 macros replace boilerplate with concrete examples: the #preview macro that generates a PreviewProvider struct, a freestanding SF symbols enum macro that parses string literal arguments via SwiftSyntaxBuilder, emits diagnostics for invalid names, and is covered by XCTest unit tests. Demonstrates attached macros (member, accessor, peer, member-attribute), the peer+accessor combo that makes a published backing property, and using SwiftSyntaxExplorer to inspect nodes.
AI-written summary · about
chapters (9)
- 0:00Introduction to Swift macros
- 2:03Understanding macro structure
- 4:20Designing a custom macro
- 7:07Creating the macro package
- 10:53Working with SwiftSyntax
- 13:52Implementing diagnostics
- 17:13Macro testing
- 18:26Advanced macro types
- 25:02Advanced macro techniques
related talks
36mHow to Write Resilient Swift code (and do it faster with Macros)
14mSession Preview
49mAre We Macro-free Yet?
13mTowards Macro-Aware C-to-Rust Transpilation (WIP)
37mManaging Side Effects with Swift
53mRefactor Your Way Forward
01h 03mKeynote: Abstraction Patterns
43mFrom Modularization to Clang and Back
