Introduction to Swift Macros

Daniel H Steinberg

⏱ 1-day-workshop
10:00-18:00, Tuesday, 21st May 2024
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.


🏷 Swift Macros

Daniel H Steinberg

Daniel is the author of more than a dozen books including the best selling books The Curious Case of the Async Cafe, A SwiftUI Kickstart, A Swift Kickstart, A Bread Baking Kickstart, and Dear Elena.

Daniel presents iOS, SwiftUI, and Swift training and consults through his company Dim Sum Thinking.

He has written apps for the iPhone and the iPad since the SDKs first appeared and has written programs for the Mac all the way back to System 7. When he's not coding or talking about coding for the Mac, the iPhone, and the iPad he's probably cooking, baking bread, or hanging out with friends.

Information on his books and videos is available on the Editors Cut website. Details on his training, and speaking is on the Dim Sum Thinking website.