Welcome to another issue of Weekly Resources where I will be compiling all the articles that I have read, the videos I have watched, and the articles I have written alongside any other thoughts and ideas each week, released on Fridays.
I also launched a series on my blog called SwiftUI Modifiers Deep Dive, releasing an article every Wednesday about a new SwiftUI Modifier, be sure to check it out!
Articles Read
swift-evolution: Attached Macros
Not really an “article” per se but if you are interested in learning more about Swift macros, reading Swift evolution proposals is a great place to start.
swift-evolution: Init Accessors
This one is a little tougher to understand without an example case for me personally, which you can find in videos watched below, but the gist of this Swift update is that it adds a new init
accessor alongside get
, set
and others when setting up a computed property. Take a look below at the Point Free video for an example and walkthrough.
Videos Watched
WWDC23 - Write Swift macros
Great first video to get you started on macros in Swift. It goes through declaring, implementing, and testing macros, and a bit of a dive into SwiftSyntax as well.
WWDC23 - Expand on Swift macros
I think you can see a trend here in this week’s learning. Going a bit further into macros, this video talks about macro roles and goes a bit deeper on implementation details.
Point Free - Init accessors in Swift 5.9
This is a great video walkthrough on how init
accessors work. Its a simpler take on the entire proposal, but it does explain in clearly.
Articles Written
SwiftUI Modifiers Deep Dive: containerRelativeFrame
This week’s SwiftUI Modifiers Deep Dive explores containerRelativeFrame
, a handy modifier that allows you to position views relative to its container.
How to Build the @Entry Macro in SwiftUI
Explore how the @Entry
macro works in SwiftUI in-depth in this article by writing your own! I basically go step by step in this one on how to write a macro by copying the functionality of the SwiftUI @Entry
macro.
Thoughts
Swift AST Explorer
The Swift AST Explorer is a really handy tool for Swift macro development. It allows you to explore Swift’s Abstract Syntax Tree. Writing macros is fairly straightforward, although using the AST is a bit cumbersome. I have found myself leaning more towards writing macros using strings instead.
Macros, @macros, #macros
I guess I really jumped into macros this week. I had fun, and they are handy, but I still don’t really see any obvious use cases. I keep thinking about anything that could be considered boilerplate, but what would you consider boilerplate? Maybe API layers that make a network call and decode JSON? One of these days I’ll find a solid use case to create my own macro.