This hands-on, one day introductory course is for experienced Swift developers who want to explore meta-programming with Swift Macros.
Contact us at firstname.lastname@example.org to book or inquire about this course for your group, company, conference, or public event.
Swift Macros gives you a lot of power to transform and customize existing Swift code. Apple takes advantage of it in the implementation of #Preview, @Observable, and @Model. We'll use these and others as inspiration to create our own Swift Macros.
We'll see an example that eliminates boilerplate code in the use of AsyncStreams. Throughout the day we look at various situations in which macros might and might not be appropriate to help you get a feel for when you should reach for this tool.
We examine the different types of macros that are available in Swift and have actual examples of why it's important to select the appropriate type. We'll consider what's involved in basic parsing before digging into parsing an Abstract Syntax Tree using SwiftSyntax to pull out the pieces you need for your macro. We put in error handling and write tests to make our macros more robust.
You need a Mac running the latest version of Xcode. You'll create projects throughout the day.
Part I - Getting Started
Exploring existing macros
The Macros Template
Part II - First steps in transforming code
Swift Syntax Builder
URL You build it
Part III - Using our macros
Macros in Macros
Part IV - Creating a variety of macros
Implementing a Member Macro