SwiftUI Changes at WWDC 2022
Join us as we share the latest updates and a glimpse into the future of UI framework design. Discover deep levels of customization, advanced techniques for layout, elegant strategies for sharing, and rock-solid structural approaches for designing an app top-to-bottom in SwiftUI. We’ll also have some celebratory fun as we play with the latest graphical effects and explore APIs.
Bring multiple windows to your SwiftUI app:
Discover how the Shortcuts app uses both SwiftUI and AppKit to create a top-tier experience on macOS. Follow along with the Shortcuts team as we explore how you can host SwiftUI views in AppKit code, handle layout and sizing, participate in the responder chain, enable navigational focus, and more. We’ll also show you how to host AppKit views, helping you migrate existing code into a SwiftUI layout within your app.
Compose custom layouts with SwiftUI:
SwiftUI now offers powerful tools to level up your layouts and arrange views for your app’s interface. We’ll introduce you to the
Grid
container, which helps you create highly customizable, two-dimensional layouts, and show you how you can use theLayout
protocol to build your own containers with completely custom behavior. We’ll also explore how you can create seamless animated transitions between your layout types, and share tips and best practices for creating great interfaces.
The SwiftUI cookbook for navigation:
The recipe for a great app begins with a clear and robust navigation structure. Join the SwiftUI team in our proverbial coding kitchen and learn how you can cook up a great experience for your app. We’ll introduce you to SwiftUI’s navigation stack and split view features, show you how you can link to specific areas of your app, and explore how you can quickly and easily restore navigational state.
Meet Transferable: a model-layer protocol that allows for effortless support for sharing, drag and drop, copy/paste, and other features in your app. We’ll explore how you can use the API for common use cases, and take advantage of advanced features to customize the behavior. We’ll also share how you can optimize for memory efficiency when dealing with large amounts of data. Whether you’re extending your models to share with other applications as strings or images or creating custom declared data types, Transferable can help you facilitate a great experience in your app.
Discover how the Shortcuts app uses both SwiftUI and AppKit to create a top-tier experience on macOS. Follow along with the Shortcuts team as we explore how you can host SwiftUI views in AppKit code, handle layout and sizing, participate in the responder chain, enable navigational focus, and more. We’ll also show you how to host AppKit views, helping you migrate existing code into a SwiftUI layout within your app.
The craft of SwiftUI API design: Progressive disclosure:
Discover the latest SwiftUI APIs to help you present windows within your app’s scenes. We’ll explore how scene types like MenuBarExtra can help you easily build more kinds of apps using SwiftUI. We’ll also show you how to use modifiers that customize the presentation and behavior of your app windows to make even better macOS apps.
Efficiency awaits: Background tasks in SwiftUI:
Background Tasks help apps respond to system events and keep time-sensitive data up to date. Learn how you can use the SwiftUI Background Tasks API to handle tasks succinctly. We’ll show you how to use Swift Concurrency to handle network responses, background refresh, and more — all while preserving performance and power.
• • •
This post will cover the most significant additions and changes to the SwiftUI framework.
Paul Hudson (tweet):
I’ve managed to explore maybe two thirds of the new API, but there’s still more to explore – I’ll update this article soon.
A list of everything new in SwiftUI after WWDC 2022.
SwiftUI has brand new navigation APIs in iOS 16 and macOS 13. They allow us to define stack-based navigation and multicolumn navigation.
NavigationSplitView
accepts acolumnVisibility
parameter with a value of type NavigationSplitViewVisibility. It lets us specify what columns we would like to show.In three-column navigation we have control over the sidebar and the middle column and in two-column navigation we can control the sidebar.
In this article we’ll be looking into how to programmatically hide and show the sidebar in two-column navigation.
Navigation was the main pain point of the framework from the very first day. Fortunately, things have changed since WWDC 22, and SwiftUI provides the new data-driven Navigation API. This week we will learn how to use the new Navigation API to build complex user flows.
From the beginning of SwiftUI we’ve had a vision to not only provide you with great declarative APIs, but also the underlying imperative mechanisms we use to build them.
Imagine having the low-level control to add custom extensions to CSS like a browser engine, to bundle them with your app, and share them in a package.
SwiftUI’s new
Layout
protocol gives you the full power and flexibility we used to implement SwiftUI’s stacks and grid to build your own first-class layout abstractions.
We take a first look at SwiftUI’s new Layout protocol and integrate the flow layout we’ve built previously.
In iOS 16 SwiftUI introduces a new API to create adaptive layouts ViewThatFits. This API allows us to provide alternative views when a certain view doesn’t fit into available space.
Layout
,Grid
, andViewThatFits
obviate the need for the vast majority ofGeometryReaders
I’ve seen in the wild. Please give them a try, you won’t be disappointed!
I kinda think that common layouts like
EqualWidth
,EqualHeight
, andHorizontalFlow
Layouts should be included in SwiftUI. We can build them ourselves with the newLayout
protocol, but why have thousands of implementations of the same common layouts?
Oh - this is so nice! ImageRenderer to take a SwiftUI view into either an
Image
or PDF context throughCGContext
.
There are over 20 new #SwiftUI
EnvironmentValues
in iOS 16 #WWDC22 ranging from Controls Input, Widgets, Scrolling and SceneKit categories.My favorites are
requestReview
andopenWindow
Starting from iOS 16 and macOS 13 we have a unified native SwiftUI API to request App Store reviews in our apps. We can read
requestReview
property from the environment and call it as a function at the appropriate time.
Starting from iOS 16 we can present resizable sheets natively in SwiftUI. In this article we’ll look into what we can achieve with the new APIs and what limitations they have in comparison with UIKit.
In WWDC21, WWDC22 Apple provide a Slack channel for people to interact with Apple engineers in digital lounges. Here I note down some interesting Q&As
I have categorized, curated, and in some cases commented the SwiftUI Digital Lounge questions.
The following chart shows the number of types that are new, deprecated, or already existed but are now extended to a new platform (e.g., Tables where only available on macOS, but now they can also be used with iOS).
[…]
The following charts show how many types, initializers, methods and properties where added every year[…]
Previously:
- Thoughts on SwiftUI After WWDC 2022
- System Settings
- SwiftUI in 2022
- How to Open a Window in SwiftUI
- Shortcuts for Mac
Update (2022-06-24): Bardi Golriz (via Dave Verwer):
Not a day goes by when I don’t benefit from the SwiftUI community’s incredibly giving spirit. It was time I gave a little back. So on a Saturday night, I began archiving all questions/answers from its WWDC22 Slack channel. Several hours later, and it was done.
Lucky7 is having problems with Transferable
and ShareLink
.
Update (2022-06-30): James Dempsey:
There is now a way to handle a double-click on a
Table
orList
in SwiftUI for macOS.