This is another huge year of updates, delivering many highly requested features such as advanced scroll view effects, container relative sizing, and even Metal shaders.
SwiftUI continues to evolve at a rapid pace, and this year has seen a huge number of improvements to scroll views, fun new SF Symbols effects, advanced support for Metal shaders, and more.
Some of these are things I’ve asked for personally, including the ability to add Metal shaders, making Color work better with Codable, adding a completion closure for animations, allowing us to animate gradients, and being able to selectively round corners of a rectangle – I’ve closed at least a dozen feedbacks just from beta 1!
Scroll view improvements
- How to make a ScrollView snap with paging or between child views
- How to disable ScrollView clipping so contents overflow
- How to make a ScrollView start at the bottom
- How to indent the content or scroll indicators in a ScrollView
- How to make views scroll with a custom transition
- How to flash the scroll bar indicators of a ScrollView or List
- How to enable vertical page scrolling
Drawing and animation improvements
- How to add Metal shaders to SwiftUI views using layer effects
- How to dynamically adjust the appearance of a view based on its size and location
- How to animate SF Symbols
- How to run a completion callback when an animation finishes
- How to create multi-step animations using phase animators
- How to combine shapes to create new shapes
- How to adjust the size of a view relative to its container
More welcome improvements
- How to add in-app purchases in SwiftUI
- How to add an inspector to any view
- How to detect and respond to key press events
- How to control which NavigationSplitView column is shown in compact layouts
- How to add haptic effects using sensory feedback
- How to tell the user that no content is available
- How to read the red, green, and blue values from a Color
- How to make buttons that repeat their action when pressed
And there’s more…
You might expect me to talk about SwiftData here, but I’m not – or at least not yet. Yes, it’s important, and yes it’s genuinely a huge step forward for all iOS developers, but I’m spending a lot of time writing test projects, experimenting, and getting answers to my questions, because I want to be really sure I understand it thoroughly before I write about it.
However, there are other interesting SwiftUI changes to discuss:
- There’s improved API for filling and stroking shapes at the same time.
- The
onChange()modifier now accepts 0 or 2 parameters, and can also be triggered by your initial value - The
foregroundColor()modifier has been formally deprecated in favor offoregroundStyle(). - Changing colors in a gradient will animate in iOS 17 and later.
- SwiftUI’s default animation is now a spring, there are many more built-in animations such as
.bouncyand.snappy, and springs are now created with much simpler API. - There’s new support for rounding some corners of a rectangle but not others.
- There’s newer, simpler syntax for making fill shapes and clip shapes:
.rect,.capsule, and so on. - When creating table views, we can now write
ForEach(users)rather thanForEach(users, content: TableRow.init)
And although it’s more of an Xcode improvement than a SwiftUI improvement, all images and colors defined in assets catalogs now have static names we can use in code rather than strings: Image(.dog) rather than Image("dog"), for example.
There are also new APIs for performing keyframe animations, new map controls, and more – I’m still digging in, writing code samples, and finding techniques that work well.
I particularly like some of the approaches taken in these new APIs, particularly the way things like scroll bar flashing, sensory feedback, and phase animations can be triggered using a simple Equatable comparison – it really lowers the complexity bar
So what about SwiftData?
The dramatic and wide-ranging changes to data management in SwiftUI are really welcome. In fact, there’s a video of me actually letting out a scream during Apple’s State of the Union session at Apple Park – I’m really glad to see it arrive.
However, it’s also something that takes care to get right. I’ll be updating my books for it – of course! – but I also want to make sure I understand the best practices for using it thoughtfully, so I hope you don’t mind a little delay while I’m conducting all my research.
Thank you for your patience!