What's new in SwiftUI
Description: SwiftUI can help you build better and more powerful apps for iPhone, iPad, Mac, Apple Watch, and Apple TV. Learn more about the latest refinements to SwiftUI, including interface improvements like outlines, grids, and toolbars. Take advantage of SwiftUI’s enhanced support across Apple frameworks to enable features like Sign In with Apple. Discover new visual effects, as well as new controls and styles. And find out how the new app and scene APIs enable you to create apps entirely in SwiftUI, as well as custom complications and all new widgets. To get the most out of this session, you should be familiar with SwiftUI. Watch "Introduction to SwiftUI" for a primer.
100% SwiftUI Apps
We can now build an entire app completely in SwiftUI.
This is a fully functional app:
@main
struct HelloWorld: App {
var body: some Scene {
WindowGroup {
Text("Hello, world!").padding()
}
}
}
- We can do so thanks to the new
App
protocol, which requires abody
of typesome Scene
. WindowGroup
lets us create scenes easily based on the platform, and more.DocumentGroup
lets us open, edit, and save document-based scenes.
LaunchScreen
- New
Launch Screen
Info.plist
key - Lets us declare standard UI components such as images, navigation bar, tab bar, background colors as the app launch screen.
- Replaces the
LaunchScreen.storyboard
.
Widgets
- Built exclusively with SwiftUI
- Widgets are just like Views, however instead of conforming to
View
, they conform to theWidget
protocol, and thebody
returns asome WidgetConfiguration
instance.
Apple Watch
- We can use SwiftUI to build custom complications
Lists
- Stacks behave more like
List
by prepending them with with Lazy (e.g.LazyVStack
) - New grid component via
LazyHGrid
,LazyVGrid
, andGridItem
Toolbar and Controls
- New
.toolbar
modifier andToolBarItem
, those are examples of semantic placements, we describe to SwiftUI the role that these toolbar items have, and SwiftUI will automatically place them properly. - We can also specify the placement in the
ToolBarItem
explicitly in its initializer
Label
- new View that combines a text and an image (in reality
Label
accepts twoAnyView
instances) Label
s adapt neatly based on the context and dynamic type size, sometimes the text might not be shown (for example on navigation bars)
- new View that combines a text and an image (in reality
ProgressView
- can display determinant and indeterminate progress
- linear and circular style
- customizable
Gauge
- used to display a value relative to a range (min/max)
- Other important modifiers
.help
.keyboardShortcut
Effects and Styling
matchedGeometryEffect
ContainerRelativeShape
- We can add a new
AppAccentColor
color assets in our bundle to have our app automatically adapt that accent color in all our UI. - We can also customize some parts of our UI with a different color than the app accent color by using the relative tint modifier such as
listItemTint
System Integration
- The new
Link
view lets open a webpage or deep link to another app, this is the equivalent of creating a button with aUIApplication.shared.open
action - drag and drop support
SignInWithAppleButton
- More integrations:
- AVKit
- MapKit
- SceneKit
- SpriteKit
- QuickLook
- HomeKit
- ClockKit
- StoreKit
- WatchKit