Sitemap

Member-only story

Factory: Macro Misadventures

Why an early attempt to add Swift Macros to Factory was a study in compromise.

8 min readMay 30, 2025

--

Press enter or click to view image in full size
Factory Logo, @2025, Michael Long

One of the new features added to Xcode last year was Swift Macros, expressions or attributes one could add to code that expand at compile time, adding features and reducing boilerplate and enabling complex behaviors without the need for manual scaffolding.

One of the better-known examples of this was @Observable, which automatically synthesized the plumbing needed for Swift’s new Observation framework.

Observable was a feature touted to save developers from writing mountains of mindless boilerplate while increasing performance across the board… albeit with a few small problems.

This article discusses why I wanted to add macros to my dependency injection project Factory, how Factory might benefit from them, and the many, many, many trials and tribulations I’ve stumbled into along the way trying to implement the silly things.

And as an experiment and in keeping with the modern age, I also leaned heavily on generative AI systems in an attempt to speed my progress along.

And let’s just say the results there were mixed as well.

But more on that later.

--

--

Michael Long
Michael Long

Written by Michael Long

A Lead Software Engineer who writes about Apple, Swift, SwiftUI, and technology. Also author of the open source projects Factory and Navigator.