What's New in SwiftUI - WWDC24
Peter Yaacoub •
Introduction
SwiftUI continues to evolve, bringing a host of new features and improvements in 2024. This year, there are significant updates across various aspects of the framework, enhancing the development experience and enabling the creation of more powerful and engaging apps.
Tab Bar
SwiftUI now allows the creation of a TabView
with Tab
, coupled with a sidebarAdaptable
tabViewStyle(_:)
. The new tab view customization provides a perfect new tab bar experience on iPadOS and macOS.
Windowing
There are several new modifiers for customizing window presentation and behavior:
presentationSizing
: Adjusts how sheets look when presented.DocumentGroupLaunchScene
: Enhances the launch experience for document-based apps.windowStyle(_:)
,windowLevel(_:)
,defaultWindowPlacement(_:)
: Fine-tune window appearance and behavior.WindowDragGesture
: Makes windows draggable.pushWindow
: Makes new windows appear by closing the previous one.
Math
SwiftUI introduces new ways to create and visualize mathematical data:
LinePlot
: Create line plots with functions.Table
: Create dynamic tables withTableColumns
andTableColumnForEach
.MeshGradients
: Add visually stunning gradients to your app.mix(with:by:in:)
: Blend colors together dynamically.
VisionOS
In visionOS, you can fine-tune effects with the new hoverEffect(_:in:isEnabled:)
view modifier and make use of updates for volumes and immersive spaces.
Input
Enhancements to input handling include:
modifierKeyAlternate(_:_:)
: For power users who use hidden menu options.onModifierKeysChanged(mask:initial:_:)
: Adjust views based on modifier key presses.pointerStyle(_:)
: Customize mouse and trackpad pointer styles.onPencilSqueeze(perform:)
andonPencilDoubleTap
: Create customized experiences with Apple Pencil.
Text
New features for text formatting and input:
- Format text with a reference date, offset, or timer.
- Access text selection with
TextSelection
. - New modifiers:
searchFocused(_:)
,textInputSuggestions(_:)
, andtextRenderer(_:)
.
Scroll
The scrolling experience is more customizable with new modifiers and methods:
onScrollGeometryChange(for:of:action:)
andonScrollVisibilityChange(threshold:_:)
: Track scrolling changes.ScrollPosition
andscrollTo(edge:)
: Control scroll positions programmatically.
Quality of Life Changes
New property wrappers and improvements:
Entry()
: Create new values forEnvironmentValues
,FocusedValues
,Transaction
, orContainerValues
.Previewable()
: CreateState
properties in previews.
Conclusion
SwiftUI 2024 brings exciting new features and enhancements, making it easier to build rich, interactive, and visually appealing applications. These updates provide developers with more tools and flexibility to create high-quality apps across all Apple platforms.