Here are 3 Swift Macros you can start using today 🤌

Hi 👋

I’ve just received a group picture that was taken on the ferry on the way back from Swift Island!

And it looks so cool that I couldn’t resist sharing with you:

Next week promises to be also quite exciting for me, because this time I’ll be speaking at the Paris iOS conference 🇫🇷 🥐 🍷

(I also plan to release the first video of a completely new format next week, stay tuned 🍿)

And now before I start this email, I have a big thank you to my sponsor of the week: RevenueCat 😼


Advertisement

RevenueCat makes adding subscriptions to your app simple🚀

Never worry about StoreKit 🤦‍♂️📱

Plus, get out-of-the-box charts and reporting for your app 📈📊

👉 Try it for free 👈


Sponsors like RevenueCat really help me grow my content creation, so if you have time please make sure to have a look at what they offer: it’s a direct support to my content creation ☺️


That’s it, Xcode 15 Release Candidate has been available since the middle of last week!

This means that we can now start using the new features of Swift 5.9 in production, including Swift Macros 🥳

Of course, Macros are quite challenging to write, so I don’t expect that many of us will start writing one in the coming days.

However, a lot of very talented people in the iOS community have spent time during the summer to implement very useful Macros!

So here’s a list of 3 Macros from the community that you can start using today!

#01 – @EnvironmentValue

If you’ve ever tried to store your own values inside of SwiftUI’s Environment, you’ve probably noticed how cumbersome it is to have to declare a new struct that conforms to EnvironmentKey each time 🥵

But thanks to the macro @EnvironmentValue, this boilerplate has now become a thing of the past:

Even better: you don’t even need to manually use @EnvironmentValue on each property!

Instead, you can use @EnvironmentStorage, which will take care of automatically applying @EnvironmentValue to each property 👌

#02 – @Spyable

If you need to implement mocks to write your unit tests, this next macro is going to save you so much time!

If you annotate a protocol with the macro @Spyable

…it will automatically generate a mocked implementation for you!

And from that, you can use this mocked implementation in your unit tests:

#03 – @SFSymbol

If you use SF Symbols in your apps, you might have been frustrated by the lack of a type safe initializer that would catch any spelling mistake at compile time 😢

However, this problem can now be solved thanks to Swift macros!

All you need is declare an enum with the symbols you want to use…

Then apply the macro @SFSymbol to this enum: it will automatically check that the symbols you are using actually do exist 😌

If you’re curious to discover even more Swift Macros from the community, I really recommend you check out this amazing GitHub repo 🔥

(I’ve actually used it to find the 3 macros in this email!)

That’s all for this email, thanks for reading it!

If you’ve enjoyed it, feel free to forward it
to your friends and colleagues 🙌

I wish you an amazing week!

❤️

Previous
Previous

Bad practice: not using throwing tests

Next
Next

Hidden feature: private properties