Member-only story
Factory: Macro Misadventures
Why adding Swift Macros to Factory is a study in compromise.
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.
Let’s dig it, shall we?