Alexito's World

A world of coding 💻, by Alejandro Martinez

Unlocking Mixins with Swift 5.9 Macros

It's been a while since the last time I thought about traits and mixins in Swift, but the WWDC23 presentations about macros brought a lot of memories from those times when I really lamented not having that functionality in the language. Thankfully, Swift 5.9 gives us a form or meta-programming that allows us to get some basic support for mixins.

It's still not fully generic since macros don't give you all the type information you need for that yet, but they are functional and usable via ad hoc macros.

But also I don't think we have a big need for them anymore, the development landscape has changed a lot since those days.

Check out this video:

Previous conversations about traits and mixins:

If you liked this article please consider supporting me