WWDC 2022. What’s new in SwiftUI


Hello everyone, I’m with you, Anna Zharkova, Lead Developer at Usetech.

Week of thematic sessions is in full swing. Today we will talk about SwiftUI, what new items have already been presented and announced.

In this version, the bet was made both on supporting new iOS features, and on improving and refining existing ones. The main directions of development of SwiftUI are:

1. Support for the new charting framework Charts

2.Navigation (own, native, native)

3. Complex controls

4.Support sharing

5.Graphics and layout

I propose to consider them in more detail.

charts

Let’s start in order with the charting API.

Looks like Apple did a great job. With this native tool, it is now quite easy to embed a graph with customizable parameters and styles in your application. Much is supported right out of the box and created with literally one line of code. For more information on how to work with this API, see the thematic videos.

Navigation

One of the most anticipated improvements in SwiftUI is navigation. I think, I will say without exaggeration, that this would not have been possible without you and me, without those who offered their approaches and ways of solving this problem. Perhaps, somewhere in some video, a lonely “thank you” for all of us was lost, but otherwise, according to tradition, Apple pretends that they thought of everything themselves. Anyway.

The NavigationView is now replaced with a special NavigationStack, inside of which there will be a NavigationLink of the new format. The new navigation links will not operate directly on the View, but on special paths to them from the data models.

There will also be (return) the ability to create a programmatic transition using the NavigationDestination construct.

Several questions immediately arise:
– how to go back one or more levels without the Back button

– whether we need lazy for View or not

The second part requires a detailed study, you need to see what the links have under the hood.

The answer to the first is: keep references to your paths in a special array and manipulate it.

To simplify the code and make it neater, Apple engineers recommend … creating a special model for storing navigation data.

You can also connect local storage and asynchronous data requests from the saved stack here.

So far, it looks like we have more options for setting up and managing navigation, but now we also need to set up more ourselves.

A special NavigationSplitView control was also introduced to create a Master-Detail UI with support for multiple levels:

Improvements and improvements also affected multi-window applications. And for macOS and iPad, special menus appeared:

advanced controls

The next item is extended and improved versions of controls. Inline styles, which were originally conceived to simplify work, brought a lot of headaches. Therefore, some of the inconveniences are fixed in the new version.

Added custom multiline TextFields

Extended version of date pickers:

There are special controls for grouping and creating a UI similar to the system one. They also provide advanced options for customizing inline styles:

Particular attention is paid to the UI and its adaptation to iPadOS. If you have not worked specifically with iPadOS, or have worked with UI for iPad for a long time, then it will be unexpected for you that it is closer to macOS in terms of UI, controls and UI capabilities.

A lot of work has been done with various forms, TableView for iPad. A lot of attention is paid to special Toolbars, their settings and capabilities. See the thematic sessions for more details.

Sharing

Native sharing in iOS came out quite powerful. Now you do not need a lot of code, fiddling with UIImagePickerController and complex decisions. Thanks to the new redesigned approach and the Transferable protocol, which we will be talking about on June 8 and 9, everything is done simply and quickly.
On SwiftUI, sharing is implemented in just a couple of lines of code:

You can also set up drag-and-drop.

See the thematic sessions for more details.

Graphics and layouts

Improvements also touched on the built-in UI graphic design features and new layouts. In the “What’s new in SwiftUI” video, they touched on the latter very superficially, promising to tell about complex markups in a thematic video.

In terms of graphics options, shadows, highlights, gradients, image relief, and more can now be easily adjusted.

It became easier to add dynamics and animation of both images and other controls:

To make it easier to create spectacular UI, a special Grid control is presented, with which you can create complex grids with different layouts and the number of rows and columns:

It is also easy to manage the parameters responsible for the arrangement of elements.

These are the main directions of changes and improvements in SwiftUI, but not all. Almost all the new APIs, SDKs and Kits presented work with the support of the declarative framework. Particular attention is paid to the work of SwiftUI with iPadOS, macOS, watchOS.
SwiftUI has not supplanted UIKit, because it is based on it, but is not going to go into the shadows either.

There are still 4 days of video ahead. Share your impressions)

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *