NOW AVAILABLE

The Case of the Vanishing Bodies: An Introduction to Swift Macros

by Daniel H. Steinberg

Margaret Eldridge
The Pragmatic Programmers

--

Daniel H. Steinberg gives us another clever and insightful book about programming in Swift. The Case of the Vanishing Bodies is an introduction to the magic of freestanding and attached Swift macros.

There’s a fair amount of boilerplate code involved in so many of our everyday tasks as Swift programmers. Until Xcode 15, every time we created a new SwiftUI View we had to create the corresponding preview code. The struct and computed property weren’t interesting in any way — they were just a necessary task we needed to perform to display a preview of our View. With the introduction of the #Preview macro, we now only need to provide the code required to create an instance of the view being displayed.

In this book, you’ll learn to create a variety of macros. You’ll get a feel for when you should and shouldn’t create them, which sort of macro you should create, and how to use SwiftSyntax to implement them. Your macros will accept parameters when appropriate and will always include tests. You’ll learn to create helpful diagnostics for your macros and even FixIts.

Now available from pragprog.com/titles/d-dsbodies.

This work was written and produced entirely by the author. We are proud to be distributing it.

--

--