WWDC24: What’s new in SwiftUI | Apple

Apple Developer
10 Jun 202423:13

Summary

TLDRSommer and Sam, engineers from the SwiftUI team, introduce exciting updates in SwiftUI that enhance app development. They demonstrate these improvements through a karaoke event planner app, showcasing new features like the flexible tab view, customizable sidebar, unified sheet presentation sizing, and immersive experience tools. They also cover advancements in Swift Charts, Controls API, mesh gradients, and animation presets for SF Symbols. The presentation highlights the ease of creating custom UI elements, improved windowing on macOS, and input method support across platforms, emphasizing the powerful capabilities now available to developers.

Takeaways

  • 🎉 SwiftUI has introduced a plethora of new features to enhance app development, including improvements in UI, accessibility, and cross-platform adaptability.
  • 📱 The new TabView in SwiftUI offers a more flexible sidebar and tab bar representation, allowing for easier UI customization and navigation.
  • 🌐 SwiftUI now supports a unified and simplified sheet presentation sizing across different Apple platforms, enhancing the user experience on iOS, macOS, and tvOS.
  • 🎨 SwiftUI introduces first-class support for mesh gradients, offering developers the ability to create visually appealing and immersive interfaces.
  • 🛠️ The introduction of a new controls API allows for the creation of custom resizable widgets that can be integrated into the Control Center or the lock screen.
  • 📈 SwiftUI now supports function plotting in Swift Charts, making it easier for developers to visualize data with LinePlot and other graphical representations.
  • 📝 The new Document Launch Scene type in SwiftUI allows developers to create more expressive and feature-highlighting launch screens for their apps.
  • 🔄 SwiftUI has added animation presets for SF Symbols, providing developers with more options to create engaging and dynamic UI elements.
  • 🖊️ SwiftUI now offers improved text editing capabilities, including programmatic access to text selection, which can be utilized for features like suggested rhymes in a lyrics editor.
  • 📱 Enhancements in windowing and input methods for macOS and visionOS apps, enabling developers to create more interactive and tailored experiences.
  • 🎤 The script highlights the development of a karaoke event planner app, demonstrating the practical application of the new features in SwiftUI for building immersive and interactive apps.

Q & A

  • What is the main topic of the video presented by Sommer and Sam?

    -The main topic of the video is to introduce and discuss the new features and improvements in SwiftUI, which are used to enhance their karaoke event planner app.

  • How has the TabView in SwiftUI been improved according to the video?

    -The TabView in SwiftUI has been improved with a new type-safe syntax, a floating tab bar above the content, and a sidebarAdaptable style that allows switching between tab bar and sidebar view.

  • What is the new feature in SwiftUI that allows for unified and simplified sheet presentation sizing across platforms?

    -The new feature is the .presentationSizing modifier, which can be used to create perfectly-sized sheets with .form or .page, or even custom sizing.

  • How does SwiftUI support custom resizable controls like buttons and toggles?

    -SwiftUI introduces a new kind of Widget called Controls that are easy to build with App Intents, allowing developers to create custom resizable controls that can be activated by the action button.

  • What new feature in SwiftUI allows developers to plot functions and draw graphs easily?

    -SwiftUI now supports function plotting in Swift Charts, making it easy to draw beautiful graphs like LinePlot.

  • How does SwiftUI enhance the table view experience in the karaoke party attendance tracker?

    -SwiftUI has introduced TableColumnForEach, allowing for a dynamic number of table columns that can adapt to the number of parties being tracked.

  • What new feature in SwiftUI allows for the creation of colorful mesh gradients?

    -SwiftUI has added first-class support for colorful mesh gradients, which can be created by interpolating between points on a grid of colors.

  • How can developers customize the launch screen of their apps using the new Document Launch Scene type in SwiftUI?

    -Developers can create a big bold title, customize the background, and add accessory views to make the launch experience unique and feature-highlighting.

  • What are the new animation presets for SF Symbols introduced in SwiftUI?

    -The new animation presets for SF Symbols are wiggle, breathe, and rotate, which add dynamic effects to symbols to draw attention or indicate ongoing activity.

  • How does SwiftUI improve the windowing experience on macOS and other platforms?

    -SwiftUI introduces improved windowing with more control over window styles and behaviors, new scene types like utility windows, and the ability to customize windows with modifiers and gestures.

  • What new input methods and interactions are available for SwiftUI apps on different Apple platforms?

    -SwiftUI now supports a variety of input methods including hover effects on visionOS, keyboard shortcuts on macOS, pointer interactions, and Apple Pencil gestures on iPadOS.

Outlines

00:00

🎉 Introduction to SwiftUI Enhancements

Sommer and Sam, engineers from the SwiftUI team, introduce the audience to the latest updates in SwiftUI. They discuss the development of a karaoke event planner app that showcases new features such as a flexible sidebar and tab bar, type-safe syntax for TabView, and customizable UI elements. The app also demonstrates improved platform-specific adaptations, unified sheet presentation sizing, and new navigation transitions. They invite viewers to explore the new features in-depth through provided resources.

05:02

🛠️ Customization and Animation with SF Symbols and Windows

The script delves into the customization options for apps with SF Symbols, including new animation presets like wiggle, breathe, and rotate effects. It also covers enhancements in SwiftUI for window management across Apple platforms, with examples of tailoring window styles and behaviors on macOS. The paragraph highlights the use of new scene types, window placement APIs, and gesture modifiers to create interactive and platform-adapted user experiences.

10:04

🖌️ Apple Pencil and Widget Interactivity

This section introduces support for Apple Pencil features in SwiftUI, allowing developers to integrate gestures like double-tap and squeeze into their apps. It also discusses the expansion of Live Activities to watchOS and the智能化 of widgets, which can now adapt to contexts and display more dynamically. The paragraph emphasizes the ease of creating engaging and interactive elements in apps, with a focus on user experience and accessibility.

15:06

📝 Text Editing and Graphics Enhancements

The script highlights new capabilities in text editing and graphics within SwiftUI. It mentions programmatic access and control over text selection, search field focus management, and text suggestions for enhanced user interaction. Additionally, it covers the introduction of a color mix modifier for graphics, precompilation of custom shaders, and refined APIs for scroll views, aiming to provide developers with more tools for creating rich and responsive app interfaces.

20:07

🎼 Concluding with Interoperability and Immersive Experiences

The final paragraph wraps up the presentation by emphasizing the improved interoperability between SwiftUI and UIKit/AppKit, allowing for more seamless integration of gestures and animations. It also touches on new APIs for working with volumes and immersive spaces, as well as text effects, to create engaging and spatial experiences. The paragraph concludes with the anticipation of a successful karaoke party, symbolizing the culmination of the discussed SwiftUI enhancements.

Mindmap

Keywords

💡SwiftUI

SwiftUI is a user interface toolkit introduced by Apple for developers to design apps for all Apple platforms such as iOS, macOS, watchOS, and tvOS. It is central to the video's theme as the speakers discuss various updates and improvements in SwiftUI that enhance app development. For instance, they mention new features like 'TabView' and 'sidebarAdaptable' to make apps more dynamic and customizable.

💡TabView

TabView is a SwiftUI component that allows developers to create a tab bar interface in their apps. In the video, the hosts discuss the new type-safe syntax for TabView and how it can be adapted to different styles like sidebars, which is crucial for enhancing user experience across different Apple devices.

💡sidebarAdaptable

The term 'sidebarAdaptable' refers to a new SwiftUI feature that enables apps to switch between different navigation styles, such as a tab bar and a sidebar view. This is highlighted in the script as a way to make apps more flexible and adaptable to various content needs and user preferences.

💡ControlWidgetButton

A ControlWidgetButton is a new kind of widget in SwiftUI that allows for creating custom resizable controls like buttons and toggles. The video mentions using App Intents to build these widgets with just a few lines of code, demonstrating the ease of creating interactive elements within the app.

💡Swift Charts

Swift Charts is a framework used for plotting graphs and charts in Swift. In the context of the video, the hosts use Swift Charts to plot an exponential function graph for their karaoke party attendance, showcasing how developers can visually represent data within their apps.

💡TableColumnForEach

TableColumnForEach is a SwiftUI API that allows for dynamically creating a number of table columns based on the data provided. It is mentioned in the script as a way for the hosts to track attendee singing data at their parties, emphasizing the adaptability of SwiftUI for various data presentations.

💡mesh gradients

Mesh gradients refer to a graphical effect where colors are interpolated on a grid to create a lattice pattern. The video discusses SwiftUI's new support for these gradients, which can be used to make app interfaces, like karaoke invites, more visually appealing.

💡Document Launch Scene

Document Launch Scene is a new type in SwiftUI for creating custom launch screens for document-based apps. The script describes how the host crafted a launch screen with a big bold title and customized background to express the app's individuality, highlighting the feature's capability to enhance the app's first impression.

💡SF Symbols

SF Symbols is a set of symbols provided by Apple for use in apps. The video mentions new animation presets for SF Symbols, such as 'wiggle', 'breathe', and 'rotate', which allow developers to add dynamic and attention-drawing effects to their symbols, enriching the visual language of the app.

💡Live Activities

Live Activities is a feature that allows apps to display real-time information and updates on platforms like the Apple Watch. The script mentions that iOS-based live activities are now automatically shown on the Apple Watch, which is an example of how developers can provide users with timely and relevant information.

💡Apple Pencil

Apple Pencil is a stylus used with Apple devices, and in the video, it is discussed in the context of new APIs in SwiftUI that support features like double-tap and squeeze gestures. This integration allows developers to create more interactive and intuitive experiences, such as showing a lyrics doodle palette in response to a squeeze gesture.

💡EnvironmentKey

EnvironmentKey is a SwiftUI feature that allows developers to pass down data to all child views in a hierarchy. The video talks about a new ease of use improvement, the 'Entry' macro, which simplifies the process of conforming to EnvironmentKey, making the development process more streamlined and less verbose.

💡onPencilSqueeze

onPencilSqueeze is a modifier in SwiftUI that allows developers to respond to the squeeze gesture made with the Apple Pencil. In the script, it is used to show a lyrics doodle palette, demonstrating how developers can leverage specific gestures to enhance app interactivity.

💡mix modifier

The mix modifier is a new feature in SwiftUI that allows for blending colors together. It is used in the video to describe how developers can create visually appealing effects by mixing colors, contributing to the overall aesthetics of the app.

💡Swift 6

Swift 6 is the latest version of the Swift programming language, which includes new features and improvements. The video discusses how SwiftUI has adapted its APIs to align with the new language mode, emphasizing compile-time data-race safety and other enhancements that benefit developers when building apps.

Highlights

Introduction to new features in SwiftUI by engineers Sommer and Sam.

Development of a karaoke event planner app showcasing SwiftUI improvements.

Enhancements to the TabView for more flexible sidebar and tab bar representations.

Introduction of type-safe syntax in TabView to catch errors at build time.

New .sidebarAdaptable tab view style for switching between tab bar and sidebar view.

Unified and simplified sheet presentation sizing across platforms.

New zoom navigation transition for expanding info in a visually appealing way.

Custom resizable controls creation with App Intents for lock screen and control center.

Swift Charts integration for function plotting and visual data representation.

TableColumnForEach for dynamic table columns based on the number of parties.

First-class support for colorful mesh gradients in app design.

Document-based app creation for editing song lyrics with a custom launch screen.

Introduction of new animation presets for SF Symbols to draw attention and indicate activity.

Enhanced windowing capabilities on macOS for custom styling and behavior.

New scene types like utility window and window customization for macOS.

Utilization of multi-window support and push window action in visionOS apps.

Custom hover effects in visionOS for reactive views based on user interaction.

Enhanced keyboard support and pointer interaction for better accessibility.

Integration of Apple Pencil features in SwiftUI for interactive controls.

Live Activities support on watchOS for iOS-based activities without additional work.

Introduction of new text formats for displaying live times and dates in widgets.

Custom container views creation with the new ForEach subviewOf API.

Ease of use improvements with the new Entry macro for environment values and more.

Enhanced accessibility features in SwiftUI with additional information for labels.

Xcode previews improvements with dynamic linking and State usage in previews.

Programmatic control over text selection and search field focus in text editing controls.

New graphics capabilities in SwiftUI with color mixing and custom shader precompilation.

Fine-grained control over scroll views with onScrollGeometryChange and visibility change detection.

Swift 6 language mode adoption in SwiftUI for compile-time data-race safety.

Improved UIKit and AppKit interoperability with SwiftUI for gestures and animations.

New APIs for volumes and immersive spaces in visionOS 2 for a realistic karaoke experience.

Custom visual effects with SwiftUI Text views for interactive karaoke lyrics.

Encouragement for developers to leverage new APIs for enhancing their apps across Apple platforms.

Transcripts

play00:07

Hi, and thanks for tuning in!

play00:09

I’m Sommer!

play00:10

And I’m Sam!

play00:11

We’re both engineers on the SwiftUI team.

play00:14

And we’re excited to tell you all about what’s new in SwiftUI.

play00:19

To help with our karaoke habit, Sam and I have been working on an app to plan

play00:23

our regular team karaoke parties.

play00:26

Our app harnesses so many improvements to SwiftUI,

play00:30

and we're excited to share those improvements with you!

play00:33

Starting with plenty of great features to make your apps feel brand new.

play00:37

Tools to refine your apps so they feel at home on every platform.

play00:42

Widespread improvements to the foundational building blocks

play00:44

of the framework.

play00:46

And a whole suite of new tools for crafting immersive experiences.

play00:50

Whew!

play00:51

That’s a lot to cover, so let’s dive right in.

play00:55

You can really freshen up your apps with SwiftUI,

play00:58

from a new tab view, to beautiful mesh gradients, and snappy controls!

play01:04

Sam and I wrote a karaoke event planner app.

play01:07

It’s primarily a side bar driven app, and in iOS 18.0,

play01:12

the sidebar has become a lot more flexible.

play01:14

With just the touch of a button,

play01:16

our main-view changes to a tab bar representation

play01:19

for showing more of that beautiful UI. The tab bar now floats above the content!

play01:26

People can even customize the experience completely to their liking,

play01:29

reordering the items and hiding infrequently used options.

play01:34

It was easy to rewrite my main view to use the new tabview.

play01:38

Now, TabView has a new type-safe syntax in SwiftUI

play01:42

to make it easier to catch common errors at build time.

play01:45

And, as your content grows, it’s simple to make your tab view more flexible.

play01:50

By just applying the new .sidebarAdaptable tab view style,

play01:54

karaoke planners can now switch between the tab bar and sidebar view.

play02:00

The sidebar looks great when you have a lot of content, like all these song lists,

play02:04

and it even has customization behavior like reordering and removing tabs,

play02:08

which is completely programmatically controllable.

play02:12

The refreshed side bar also looks great on tvOS,

play02:15

and you can style the tab view to appear as a sidebar

play02:18

or as a segmented control in the toolbar on macOS!

play02:23

Sheet presentation sizing is now unified

play02:26

and simplified across platforms.

play02:28

You can use the .presentationSizing modifier

play02:31

to create perfectly-sized sheets with .form or .page, or even use custom sizing.

play02:38

SwiftUI supports a new zoom navigation transition too,

play02:42

and I can use it to make expanding info on a party look gorgeous.

play02:48

For more on the new TabView check out

play02:50

"Improve your tab and sidebar experience on iPad".

play02:54

And to dive deeper into new animations watch

play02:57

"Enhance your UI animations and transitions".

play03:01

You can now create your own

play03:03

custom resizable controls such as buttons and toggles

play03:07

that live in control center or the lock screen

play03:09

and can even be activated by the action button.

play03:13

Controls are a new kind of Widget that that are easy to build with App Intents!

play03:17

With just a few lines of code, I can create a ControlWidgetButton

play03:21

to get the WWDC karaoke party started at a moment’s notice!

play03:27

To learn how to use the new and powerful controls API

play03:31

to customize your configurable buttons and toggles, check out:

play03:35

"Access your app's controls across the system."

play03:38

Sam and I have been working hard

play03:40

to grow our karaoke party attendance.

play03:43

I think an exponential function seems like very reasonable goal.

play03:49

Function plotting in Swift charts makes it easy for me draw beautiful graphs,

play03:53

like this LinePlot.

play03:55

I’ll go ahead and graph the actual attendance too.

play03:59

Oof, not quite there yet.

play04:03

To dig deeper into the improvements in Swift Charts, catch

play04:06

"Swift Charts: Vectorized and function plots".

play04:10

As a data nerd, I also like to keep track

play04:13

of how much the attendees are singing at the parties.

play04:17

Using TableColumnForEach, I can now have a dynamic number of table columns

play04:22

for however many parties Sam and I have!

play04:25

To boost our attendance numbers,

play04:27

I think we should send out some colorful party invites!

play04:31

SwiftUI has added first class support for colorful mesh gradients.

play04:36

By interpolating between the points on a grid of colors,

play04:39

you can create a beautiful lattice!

play04:43

This sounds like the perfect way make our karaoke invites as snazzy as our parties!

play04:51

Now that the Karaoke Planner App is looking fresh,

play04:55

Sam and I want to have a little extra fun by customizing our lyrics!

play04:59

So, we’ve also built a document-based app

play05:02

for editing the words to our favorite songs.

play05:04

I crafted this launch screen to express my app’s individuality

play05:08

and highlight its features using the new Document Launch Scene type.

play05:13

I created a big bold title,

play05:15

customized the background and added some fun accessory views

play05:19

to really make my launch experience pop!

play05:22

To learn more about all you can do with document based apps,

play05:26

like custom document icons and templates watch

play05:29

“Evolve your document launch experience”

play05:33

I’m going to put a finishing touch on my launch screen now,

play05:37

using a symbol effect on my music notes!

play05:40

Wow, my symbols really do wiggle wiggle.

play05:45

Apps can now adopt three new animation presets for SF Symbols.

play05:50

The wiggle effect oscillates a symbol in any direction or angle to draw attention.

play05:55

The breathe effect smoothly scales a symbol up

play05:59

and down

play06:01

to indicate ongoing activity.

play06:03

And the rotate effect spins some parts of a symbol around a designated anchor point.

play06:10

Some of the existing presets have also been enhanced with new features.

play06:15

For example, the default Replace animation now prefers a new MagicReplace behavior.

play06:20

With MagicReplace, symbols smoothly animate badges and slashes.

play06:28

These are just a few of the enhancements in SF Symbols 6.

play06:33

To learn more watch “What’s new in SF Symbols”.

play06:37

SwiftUI brings great improvements to making your apps

play06:40

feel at home on any of Apple’s platforms.

play06:44

With improved windowing, more control over input and lots of glanceable content,

play06:49

your apps can take advantage of whatever platform they’re on.

play06:53

You can now tailor the style and behavior of windows on macOS.

play06:58

In my lyric editor app on macOS,

play07:00

I have a window that shows a single line preview.

play07:03

I used the new plain window style to remove the default window chrome.

play07:08

And gave it a floating window level so it shows on top of any other windows.

play07:13

I used the defaultWindowPlacement API to place it at the top of the screen,

play07:18

so it doesn't cover-up the rest of my lyrics;

play07:22

I took into account the size of the display,

play07:24

and the size of the content, to place it in the perfect spot.

play07:29

I also added a WindowDragGesture to the content view of the preview

play07:34

so I can adjust its position on screen by dragging it around.

play07:40

There are new scene types too, like utility window!

play07:43

To learn more about ways to customize the style and behavior of your windows, watch

play07:48

“Tailor macOS windows with SwiftUI!”.

play07:52

This multi-window lyrics editor app works great on visionOS too!

play07:58

Recently my fellow karaoke pal Andrew

play08:01

showed me how he’s using this new push window action in the Botanist app

play08:06

to help him keep his most important content focused!

play08:09

pushWindow can be used to open a window and hide the originating window.

play08:15

I definitely want to do the same thing in my Lyrics editor,

play08:18

so I’ll use the pushWindow environment action to focus on my lyric preview.

play08:24

Learn more in the video: "Work with windows in SwiftUI".

play08:28

SwiftUI gives you many new tools for taking advantage

play08:32

of the unique input methods each platform offers.

play08:36

In visionOS, you can make views react when people look at them,

play08:39

place a finger near them, or move the pointer over them,

play08:43

all while preserving people’s privacy.

play08:46

Within the new closure-based hoverEffect modifier,

play08:50

I can control how the view looks as it transitions between the active

play08:53

and IN-active states

play08:56

To learn how you can also coordinate multiple effects,

play09:00

control the timing of an effect,

play09:01

and respond to accessibility settings, check out

play09:05

“Create custom hover effects in visionOS.”

play09:09

Great iPadOS, macOS, and visionOS apps provide great keyboard support.

play09:15

In the main menu on macOS, I have an item to open my preview window.

play09:21

I've added the new modifierKeyAlternate modifier, and on press of the option key

play09:26

I can reveal a secondary item to preview in full-screen.

play09:31

For low level control,

play09:32

any view can respond to modifier key press state changes.

play09:36

I updated the lyric editor to use onModifierKeysChanged.

play09:41

So when I hold down option, I can see and adjust an extra alignment guide

play09:45

for where the bouncing ball lands on the lyrics.

play09:49

Pointer interaction is another important form of input across many devices.

play09:55

The pointerStyle API lets you customize the appearance

play09:58

and visibility of the system pointer.

play10:01

Since I made my lyrics resizable,

play10:03

I’ll apply an appropriate frameResize pointer style on each resize anchor.

play10:10

New in iPadOS 17.5,

play10:13

SwiftUI has support for features of Apple Pencil and Apple Pencil Pro

play10:18

like double-tap and squeeze.

play10:23

With .onPencilSqueeze, I can gather information from the gesture

play10:27

and see what action is preferred.

play10:29

In this case, I’m going to show my lyrics doodle palette

play10:33

under the pencil’s hover location so I can mark up lyrics with fun drawings.

play10:38

To learn more about all the new Apple Pencil APIs, head over to

play10:42

"Squeeze the most out of Apple Pencil".

play10:45

Widgets offer glanceable information and key interactions with your apps.

play10:50

And now that Live Activities have also come to watchOS,

play10:53

your iOS based live activities will automatically show up on Apple Watch,

play10:58

without any work on your part!

play11:01

Sam and I already have this live activity to review song lyrics on the go,

play11:06

and I can see it showing up automatically on my Apple Watch!

play11:10

To make it look really amazing, I can use the new small .supplementalActivityFamily

play11:15

to tailor the content for watchOS, showing more lyrics at once. Nice!

play11:21

And to allow our singers to advance the lyrics using double tap,

play11:25

I can apply the .handGestureShortcut modifier.

play11:30

I also want to be sure that I always know when I’m up next at a karaoke event,

play11:34

so I added a widget to my Planner app

play11:36

using the new reference date format style to show a countdown to Karaoke o’ clock!

play11:44

Text now has additional formats for the display of live times and dates

play11:49

that work great in widgets and live activities!

play11:53

These formats include date references,

play11:56

date offsets and timers.

play11:58

Each format is deeply customizable down to its components,

play12:03

and can even adapt to the size of its container.

play12:07

Widgets are smarter now too.

play12:09

Specify relevant contexts so the system can more intelligently surface them

play12:13

in places like smart stacks.

play12:15

With this, my countdown widget can show up automatically

play12:19

at a specified time, or when a singer gets close to a planned karaoke venue!

play12:25

Hey Sommer, How’s the lyrics editor coming along?

play12:27

I’ve been thinking up lyrics for my next solo, "Cupertino Dreamin",

play12:31

and I’ve gotta get it written down before I forget!

play12:33

It’s going great! I just used it to write some lyrics

play12:36

for “Smells Like Scene Spirit”, it’s gonna rock.

play12:40

Nice, we can try to slot that in towards the end of the setlist.

play12:43

That reminds me: the setlist! Is it gonna be ready for the WWDC karaoke party?

play12:48

You bet Sommer.

play12:50

The theme for the songs is all of SwiftUI’s great new Framework foundations.

play12:55

SwiftUI has added all sorts of new API

play12:58

that make working with the framework feel easier than ever,

play13:01

Including improvements to the core components of SwiftUI,

play13:04

new ways to use foundational APIs, and ease of use enhancements.

play13:10

You can now create your own custom container views.

play13:13

A new API on ForEach, subviewOf,

play13:16

lets you to iterate over the subviews of a given view,

play13:19

like in this example where I'm wrapping each subview in its own card view.

play13:24

You can use this to make custom containers

play13:26

that have the same capabilities as SwiftUI’s built in containers

play13:29

like list and picker,

play13:31

including mixing static, and dynamic content supporting sections,

play13:36

and adding container specific modifiers.

play13:40

To learn more about custom containers and the SwiftUI fundamentals behind them,

play13:44

be sure to check out "Demystify SwiftUI Containers".

play13:48

New ease of use improvements make working with SwiftUI easier than ever.

play13:53

Instead of having to write out a full conformance to EnvironmentKey,

play13:56

and an extension on environment values,

play13:58

you can now just write a simple property with the new Entry macro.

play14:02

Best of all, it doesn’t just work with environment values.

play14:06

The entry macro can also be used with FocusValues,

play14:09

Transaction, and the new ContainerValues as well.

play14:13

You can now attach additional information

play14:15

to SwiftUI's built in accessibility labels.

play14:18

That means you can add additional accessibility information to a control,

play14:22

without overriding the framework provided label.

play14:25

Be sure to check out "Catch up on accessibility in SwiftUI"

play14:28

to learn about all of SwiftUI’s amazing new accessibility features,

play14:32

such as conditional modifier support, and app intent based accessibilityActions.

play14:38

Xcode previews has a new dynamic linking architecture

play14:42

that allows you to switch between a preview, and build-and-run

play14:45

without needing to re-build your project, increasing your iteration speed.

play14:50

And it’s now easier to set up Previews too.

play14:53

You can now use State directly in previews using the Previewable macro,

play14:58

eliminating the boilerplate of wrapping your preview content in a view.

play15:02

There are now new ways to work with text and manage selection.

play15:06

SwiftUI now offers programatic access to,

play15:09

and control of text selection within text editing controls!

play15:14

The contents of my selection binding

play15:15

update to match the selected text of the lyric fields.

play15:19

Now I can read properties of the selection, such as the selected ranges.

play15:24

I can use this to show suggested rhymes for selected words in the inspector.

play15:30

With .searchFocused,

play15:31

you can programmatically drive the focus state of a search field,

play15:34

meaning you can check if a search field is focused on,

play15:36

and programmatically move focus to and from the search field.

play15:42

You can now add text suggestions to any text field.

play15:45

I'll use this to provide suggestions for how to finish a line.

play15:49

The suggestions appear as a drop down menu,

play15:51

and when I pick an option my textfield updates with the selected completion.

play15:55

SwiftUI also has new graphics capabilities.

play15:59

You can now beautifully mix colors together.

play16:02

A new mix modifier on color blends it with another Color by a given amount.

play16:07

We’ve also extended the custom shader feature

play16:10

with the ability to precompile shaders before their first use,

play16:13

so you can avoid frame drops caused by lazy shader compilation.

play16:18

There are a bunch of new APIs to give you fine grained control of your scroll views.

play16:24

You can now have deeper level of integration with the state of a ScrollView

play16:28

with .onScrollGeometryChange,

play16:30

which lets you performantly react to changes in things like content offsets,

play16:34

content size and more. Like with this "back to invitation" button,

play16:38

which appears when I scroll past the top of the scroll view's contents.

play16:43

You can now detect when a view’s visibility has changed due to scrolling!

play16:46

Letting you create great experiences

play16:48

centered around content moving on or off screen, like this auto-playing video.

play16:54

Not only do you have more programatic control over your scroll view,

play16:57

but you also have more scroll positions

play16:59

to programmatically scroll to, like the top edge!

play17:04

There are all sorts of additional knobs for you to turn to really dial in

play17:08

on your perfect scrolling experience

play17:10

like turning off bouncing along a given axis, programmatically stoping scrolling,

play17:14

finely controlling your content alignment, and more.

play17:18

The new Swift 6 language mode enables compile-time data-race safety,

play17:22

and SwiftUI has improved its APIs

play17:24

to make it easier to adopt the new language mode in your apps.

play17:28

Views in SwiftUI have always been evaluated on the main actor,

play17:32

and the view protocol is now marked with the main actor annotation to reflect that.

play17:36

That mean all types conforming to View

play17:38

are implicitly isolated to the main actor by default.

play17:42

So if you were explicitly marking your Views as main actor,

play17:45

you can now remove that annotation without any change in behavior.

play17:49

The new Swift 6 language mode is opt-in,

play17:52

so you can take advantage of it whenever you're ready.

play17:54

To learn more about compile time checking,

play17:57

be sure to watch "Migrate your app to Swift 6".

play18:01

SwiftUI was designed not just for building brand new apps,

play18:04

but also building new features in existing apps written with UIKit and AppKit.

play18:09

Great interoperability with these frameworks is critical.

play18:13

We made significant improvements to the integration of gestures and animation.

play18:17

You can now take any built-in or custom UIGestureRecognizer

play18:21

and use it in your SwiftUI view hierarchy.

play18:24

This works even on SwiftUI views that aren't directly backed by UIKit.

play18:29

And the interoperability improvements go the other way as well.

play18:33

UIKit and AppKit can now take advantage of the power of SwiftUI animations.

play18:39

SwiftUI defines a new animate function on UIView, and NSAnimationContext,

play18:44

allowing UIKit and AppKit changes

play18:46

to be animated using in-process SwiftUI animations.

play18:51

Velocity is even automatically preserved for gesture-driven animations,

play18:55

just like in SwiftUI views.

play18:57

And UI and NSViewRepresentable context

play19:00

provide new API for bridging animations started in SwiftUI

play19:03

into UIKit and AppKit, ensuring animations run perfectly in sync,

play19:08

even across framework boundaries.

play19:11

For more on using animations across frameworks, be sure to check out

play19:15

"Enhance your UI animations and transitions".

play19:18

Those foundational improvements look great.

play19:21

Now, all that’s left to is practice my karaoke skills,

play19:25

and then I can get together with Sommer and host the party.

play19:27

SwiftUI’s new tools for crafting experiences

play19:30

will help with both building a great practice app,

play19:32

and setting up the event to be a success.

play19:36

New APIs for working with volumes, and immersive spaces,

play19:39

as well as new text effects will help bring our karaoke experience to life.

play19:44

To practice my beautiful vocals, I’ve built a visionOS practice app,

play19:48

featuring a microphone in a Volume.

play19:50

In visionOS 2, volumes can show a baseplate.

play19:53

This helps you get a sense of the bounds of the Volume,

play19:56

and guides you to the window controls, including the new resize handle.

play20:00

Our microphone already has a microphone stand base,

play20:03

so I like the look of it without the system provided baseplate.

play20:06

I'll use the .volumeBaseplateVisibility modifier

play20:09

to disable the system provided baseplate. Nice!

play20:14

I also made my microphone rotate to always face the singer

play20:17

using the new .onVolumeViewpointChange modifier.

play20:21

This is called any time I move to a new side of the Volume,

play20:24

letting me react to changes in how it’s being viewed.

play20:27

I’ve got my microphone, now I need a place to put it,

play20:30

and there’s no better place to sing karaoke than a moody karaoke lounge.

play20:35

I’ve already got a beautiful immersive space,

play20:38

and I can now control the allowed immersion levels.

play20:42

By choosing an initial immersion of fifty percent, and a minimum of forty,

play20:46

I can help singers ease into the karaoke lounge.

play20:54

To help set the vibe, I can now apply effects

play20:56

to the passthrough video around my progressive immersive space.

play21:00

I could use preferred-surroundings-effect to dim video passthrough

play21:03

or to really make our karaoke experience special,

play21:06

I can use colorMultiply for some cool mood lighting!

play21:11

Ooooh, that’s fantastic.

play21:15

For more on improvements to volumes and immersive spaces,

play21:17

including new ways to attach ornaments and specify supported viewpoints

play21:21

be sure to check out “Dive deep into volumes and immersive spaces”.

play21:28

The stage is set but before we start the party,

play21:31

we’ll need lyrics we can follow along with!

play21:34

You can now extend SwiftUI Text views with custom rendering effects

play21:38

and interaction behaviors. I can use this to build a word highlighting effect

play21:42

for our karaoke lyrics.

play21:44

My karaoke renderer creates a copy of the text

play21:47

behind the original drawing, which is blurred. and has a tint,

play21:51

making the text look like it's glowing purple!

play21:54

By applying this highlight effect

play21:56

to only certain words, and adding some final polish,

play21:58

I can make some truly incredible effects, like this karaoke word highlighting.

play22:05

To learn all about how to create these amazing text effects, be sure to check out

play22:09

"Create custom visual effects with SwiftUI."

play22:12

Alright Sommer, I think we’ve done all of our party prep.

play22:16

It really is coming together!

play22:18

These changes to SwiftUI really helped Sommer and I make the most of our apps,

play22:22

and we want you to make the most of yours too.

play22:25

If you have a sidebar-based iPad or tvOS app,

play22:30

leverage the new tab view APIs to allow for more flexibility,

play22:34

and for document based apps, enhance your new document launch experience.

play22:39

Add new windowing and input capabilities to your macOS and visionOS apps.

play22:44

Make the most of your live activity by fine-tuning your experience on watchOS.

play22:49

And take advantage of the new capabilities

play22:51

in volumes and immersive spaces on visionOS.

play22:54

It’s looking like a good year to be a SwiftUI developer!

play22:57

And karaoke singer.

play22:59

Alright Sam, are you ready?

play23:01

I was born ready Sommer.

play23:03

Hey Siri, Start the Party!

Rate This

5.0 / 5 (0 votes)

Related Tags
SwiftUIApp DevelopmentKaraoke PlanneriOS 18.0TabViewControls APISwift ChartsLive ActivitiesApple PencilVolume Rendering