What’s new in SwiftUI
SwiftUI has been evolving since the day it was announced in 2019. Every year, Apple adds new APIs and SwiftUI becomes more and more powerful. At the time of this writing, it is possible to create an iOS app exclusively using SwiftUI, without having to integrate UIKit. Since the previous edition of this book, Apple added new functionality to SwiftUI.
In WWDC 2022, Apple added new features to SwiftUI, improved some existing features, and even deprecated some of the APIs just introduced a few years ago. These are the most relevant features:
- Swift Charts, which allows you to create data visualizations across all Apple platforms
- New data-driven navigation with
NavigationStack
andNavigationSplitView
- Enhancements to
Form
, to support multi-platform apps with a single code base:LabeledContent
view to display pairs of data, like key-value pairs or title and description, inside forms- Deeper customization of multi-line
TextField
instances - New
MultiDatePicker
control to select more than one date - New mixed-state controls for
Toggle
andPicker
views and a new format forStepper
views.
Table
, introduced in macOS 12, now available on iPadOS 16 and iOS 16, and new toolbar customization for iPadOSPhotosPicker
view, a multi-platform and privacy-preserving API for picking photos and videosShareLink
view, which enables the presentation of the share sheet even in WatchOSTransferable
protocol, to share data between apps- ShapeStyle extensions like
gradient
andshadow
, which can also be applied to SFSymbols Grid
, to arrange content in a two-dimensional wayLayout
protocol to create full-custom layouts
In WWDC 2023, Apple added more functionality to SwiftUI. These are the most relevant features:
- Interactivity and animation added to widgets
- Improvement to Xcode previews with a new
Preview(_:traits:body:)
macro that supports UIKit and AppKit out of the box - Native SwiftUI support for MapKit
- Interactivity and pie charts added to Swift Charts
- Navigation, date pickers, and toolbars available in WatchOS 10
SwiftData
, a successor ofCoreData
, used to persist data between app launches- The
Observable
macro, and new@State
,@Environment
, and@Bindable
property wrappers, offering a new way of sharing data throughout the app - New powerful animations with the new spring animation, the
PhaseAnimator
struct, and the Keyframe Animator andCustomAnimation
protocol - Inspector, a new modal presentation with the
inspector(isPresented:content:)
view modifier - Symbol Effects, animated symbols added to SF Symbols 5
- New powerful scrolling APIs: transition effects, scroll position, paged scrolling, and inset control
- Enhancements to list and tables: item selection, expanding sections programmatically, column visibility, column header visibility, hierarchical rows, and alternating row background
- New dialog customizations, new gestures, and new input events