Shiny & New
Swift 5.9 is now available! It’s a major new release that “adds an expressive macro system to the language, parameter packs, an improved expression evaluator while debugging, enhanced crash handling, Windows platform improvements and more.”
In the latest WWDC, we got introduced to the newest animation modifiers that can either run continuously or get triggered. If you’d like more details, you can read about Animating with PhaseAnimator in SwiftUI. And if you’re up for an even deeper dive into more than just modifiers — like SwiftData, TipKit and others — the Mastering SwiftUI book has now been updated.
Another big question is: to closure or to function? And the short answer is: Don't use escaping closures in SwiftUI. The views are lightweight functions and run best when the view takes closures in the initializer. Speaking of, also worth mentioning is that you definitely don’t want to run expensive tasks in the view’s initializer, as it might get called very often; to know how to load data in the view’s body, you can read about running code when your view appears.
Tips & Tricks
We recommend checking out this idea on how to implement pagination with SwiftUI's List view — so that you can allow users to continuously scroll through content.
On to lists. Since nearly every modern app now features a list of items, SwiftUI offers some nice tricks that can help you with drag & drop features. Take a look at how to enable drag reordering in SwiftUI lazy grids and stacks.
Staying on the Safe Side
Keep your code reusable and well-architectured with app intent-driven development in Swift and SwiftUI. You can extend custom functionality and data to support system-level services like Shortcuts, Siri, Spotlight and the Action button.
Let’s not forget about testing your code, which is just as important as the new features. For some help, you can find a little testing strategy here: Long Live The Test Pyramid. And last but not least, a bit of advice on keeping threads safe in Swift with locks!