Swift Macros
summary
Shows how to build two working compiler plugins using Xcode and SwiftSyntax: a freestanding macro that expands a string literal into URL("https://...") and emits compile‑time errors if the argument isn’t HTTPS, and an attached macro that scans non‑static properties and generates an extension listing their names. Live demos run and unit tests pass. Notes practical costs: SwiftSyntax adds ~30s debug builds (up to ~4min release on M1), debugging requires running macro tests with breakpoints, and formatting fragility breaks tests.
AI-written summary · about
chapters (10)
- 0:00Introduction and thanks
- 1:08What are Swift macros
- 4:22Creating a new macro
- 8:03Exploring SwiftSyntax
- 15:45Building first macro
- 17:59Secure URL macro
- 24:07Listable properties macro
- 31:21Macro shortcomings
- 33:55Debugging macros
- 34:18Recap and resources
related talks
37mSwift Macros: The Key to Efficient and Elegant Code
21mUnlock the Potential of Swift Code Generation
44mSwift Macros: Simpler, Cleaner, Faster
33mMaking Your Own Tools Using SwiftSyntax
35mImplementing a Macro
27mAST Meta-programming
22mImproving Swift Tools with libSyntax
42mAvoiding macros with inline and derived
