Xcoding with Alfian

Software Development Videos & Tutorials

WWDC 2022 - Platform State of the Union Recap | Swift 5.7, SwiftUI 4.0, System Experiences Latest APIs

Alt text

WWDC 2022 has just been started today. There are so many great software announcements such as iOS/iPadOS 16, macOS 13 Ventura, watchOS 9, and tvOS 16. From hardware side, MacBook Air/Pro with M2 chipset are also announced as well.

In this article, I am going to give a recap on all the new software technologies that Apple Engineers announced during the Platform State of the Union keynote from Swift, SwiftUI, and System Experiences APIs.

Xcode Cloud

Alt text

Xcode Cloud is a CI/CD service build into Xcode and hosted in Cloud. It supports development for all Apple platforms. It integrates with TestFlight and App Store Connect as well as every major git based source control provider. It even has REST APIs to help connect to other aspects of your development workflow.

It was announced at WWDC 21 last year and has since been in developer preview. Today Apple makes Xcode Cloud publicly available to all developers.

Alt text

Apple is offering 25 hours/month subscription fee to all Apple Developer Program members through end of 2023. Then, we're be able to subscribe to other tiers right from the Developer app this summer.

Vision For Platform

Alt text

A great developer platform provides tight integration between programming language, frameworks and tools. With these three complement one another, it benefits everyone. Customers get a consistent experience, like scrolling that always feels perfect. And developers are able to focus time and effort on what makes the app unique.

Objective-C, AppKit/UIKit, Interface Builder

Alt text

They have empowered generations of developers. These technologies were built for each other, and Apple ensures that it will continue to serve them well for a long time to come.

What's next for Developers

Alt text

As time goes by new abstractions become necessary. The next generation of the technologies are Swift, SwiftUI, and Xcode Previews.

Current State of Swift and Upcoming 5.7 Features

Alt text

Open Source Swift Community had announced new initiatives like Diversity in Swift and the Swift Mentorship Program, and advancing the language with working groups on topics like Swift on server, and C++ interoperability.

Swift Concurrency

Alt text

Swift Concurrency dramatically simplified reading and writing code that runs in parallel, and has been a huge hit, with more than 40,000 apps in the App Store adopting it in just the first year.

Alt text

It's now possible to deploy code with Swift Concurrency to all operating systems released in the last three years

Swift Async Algorithms

Alt text

This year, there's a new, open-source package that brings concurrency to Swift's rich set of existing sequence algorithms. It's called async algorithms.

Alt text

For example, where Swift's sequence protocol supports a zip algorithm to combine two sequences, async algorithms brings a version for zipping together two asynchronous sequences.

Because async sequences are integrated directly into the Swift language, they use familiar constructs like 'for' loops that, thanks to the async/await syntax, looks like regular straight-line code. You're also able to use the familiar try/catch pattern to handle things like network failures from asynchronous data streaming over the network.

Alt text

Swift now includes a new set of clock types for representing time units, and async algorithms builds on them to provide many time-based algorithms, like throttle here, which can help slow down updates from a sequence.

Distributed Actors

Alt text

Distributed actors can communicate across multiple processes or devices. The "distributed" keyword marks these actors and methods that can be accessed remotely, whether that's between separate processes on your Mac, peer to peer between different devices, or from a device talking to your backend written with Swift on Server.

Just as actors help Swift protect your state data from race conditions, distributed actors help Swift make them available outside your process, using a pluggable transport mechanism. The Swift compiler can then perform checks that help guarantee correct behavior in a distributed environment

New String Regular Expression Literal & Builder

Alt text

They're built directly into the language, allowing the Swift compiler to check for correctness. And they unlock the power of Swift's type system when you're extracting information with a regular expression. And they take full advantage of Swift's best-in-class Unicode support.

Example:

Alt text
Alt text

Generic Collection some Keyword in Function Parameter

Now in Swift, writing a function that accepts some collection of generic type is as easy as using the some keyword to tell Swift about the parameter. You get the same meaning, but with less code.

Now this code:

Alt text

Can be written with lesser code and easier to read:

Alt text

Store Dynamic Any Collection Type

Alt text

You might need store dynamic type of collection, like with this music library's array of playlists, which might need to contain different types of collections of songs– sets of songs, or arrays of songs. That's where the new 'any' keyword can help. The 'any' keyword is built right into Swift, and allows you to express a type that can hold any collection of songs. And it works seamlessly with generic functions too.

Package Plugins for Swift Package Manager

Alt text

This year, the Swift Package Manager is amplifying the ways you can create and build code with all-new Package Plugins. Plugins are Swift packages you can add to your project as easily as any other dependency. They download and build automatically on a fresh checkout, except instead of being code in your app, they're code that helps build your app.

Alt text

Package Plugins can be invoked from the command line or within Xcode, either as part of your build phase or on-demand. They run in a sandbox environment which prompts you for permission before reading or modifying your code.

Alt text

There are endless possibilities for extending your workflow with Package Plugins. You could use them to lint and format your code to match the team style guide with packages like SwiftLint or SwiftFormat or automatically generate source code at build-time with tools like Sorcery.

Alt text

With Swift package plugins, you can create your own commands, customize builds locally and in Xcode Cloud, and then share those plugins with others.

Other Swift 5.7 Features

Alt text

Swift has some impressive changes under the hood. Building Swift projects is quicker than ever. Thanks to new parallelization efforts, link time is up to twice as fast. And the Swift concurrency runtime is now more tightly integrated with the OS to better ensure the priority of your asynchronous tasks, helping your apps stay efficient and responsive.

Launch time for apps written in Swift is dramatically faster on iOS 16, with apps like Lyft or Airbnb launching almost twice as fast thanks to improvement in the dynamic linker.

With these under-the-hood improvements, new abilities in tooling, an evolved syntax that's easier to read and write, and improvements in concurrency, there has never been a better time to develop in Swift.

SwiftUI 4.0

Alt text

Since its introduction in 2019, Apple has been continually expanding SwiftUI's API coverage, guided by the developers feedback. This year, it is even easier to adopt SwiftUI incrementally in existing apps, and Apple have made some exciting enhancements to its power and flexibility.

All New Navigation API

Alt text

The new navigation API makes it easy to express the style of navigation that best fits the needs of your app. With robust programmatic control over the presentation of your app's views, you can easily save and restore selection, and even replace the full contents of a navigation stack. This is really useful when handling important behaviors like setting the launch state of your app, managing transitions between size classes, and responding to deep links.

New Grid API

Alt text

A new Grid API, which makes it easier to lay out a set of views aligned across multiple rows and columns.

All New Custom Layout API

Alt text
Alt text

The custom layout API gives you the flexibility to build any type of layout you want. For example, you could create a flow layout where your views are arranged like the content of a newspaper, wrapping to the next column when more space is needed. Or you could create a radial layout that draws your views in a circle, like the numbers on a watch face.

Half Sheets

Alt text

A Secondary views that slide above a main view. These are great to provide quick access to information on smaller screens.

Share Sheet with new Transferable Protocol

Alt text

SwiftUI now supports Share Sheets, so your app can easily leverage all of the Share extensions available on a user's device. Share Sheet support is powered by the new Transferable protocol, which introduces a type-safe API for transferring app data.

Host SwiftUI View in UIKit Collection View Cell

Alt text

Use a special collection view cell that can host SwiftUI views to adopt SwiftUI incrementally in existing UIKit apps. If you already have a collection view in your UIKit app, you can now write custom cells using SwiftUI's declarative syntax. These cells are tightly integrated with UIKit, supporting swipe actions, cell backgrounds, and all the other features of UICollectionView.

Swift Charts

Alt text

Swift Charts is a highly customizable charting framework built on top of SwiftUI that makes it easy to create gorgeous visualizations. It uses the same declarative syntax as SwiftUI to make it easy to read and write code which conveys visual information.

Alt text

Swift Chart lets you customize the presentation of information to best fit the needs of your app to create everything from line and bar charts to more sophisticated examples like heat maps and stream graphs, and many, many more types.

Alt text

Charts have support for accessibility features, customizable VoiceOver experience. Being built on SwiftUI also means it supports animation and works across all devices.

SwiftUI Redesigned Xcode Preview Canvas

Alt text

The redesigned preview area makes it easier than ever to see how view looks in different environments.

Alt text

See view in Dark and Light model look at layout in every interface orientation, all without adding a single additional preview.

Flexible Layout with ViewThatFits

Alt text

ViewThatFits provides dynamic switch between a vertical and a horizontal stack, depending on the available space.

Navigation Split View

Alt text

All new NavigationSplitView with a Sidebar to track the selection and a NavigationStack that changes its content as the sidebar selection changes.

Alt text

Supported Destination Settings to add supported platforms in 1 click

Alt text

It's now only a few clicks add supported destinations such as macOS, AppleTV from Xcode Target General Settings.

With just a single target backing your app, you can share almost all your code, and SwiftUI makes your app look great on each platform.

Menu Bar Extra View for macOS

Alt text

New MenuBarExtraView for macOS to add icon on Menu Bar just like Wi-Fi and Spotlight.

Apple SwiftUI Adoption in Apple System Apps & System Interfaces

Alt text

Apple is continuing to expand adoption of SwiftUI across system apps and system interfaces. For example, iOS's new Lock Screen widgets were designed from the ground up using SwiftUI. The new Font Book app was completely rewritten with it. And the modern, forward-looking design of the new macOS System Settings app was built using it.

System Experience New API

Alt text

Apps are about turning ideas, code, and APIs into user experiences. And the best apps are the ones that can meet users where they are in the moment. Apple have created ways to help you take user experience beyond your apps, and build it into the system experience on Apple devices.

Lock Screen & watchOS 9 Complications powered by WidgetKit, New Widgets.

Alt text

In reimagining the Lock Screen, Apple set out to make it even more personal and beautiful, while improving everyday utility. As part of this, they knew they needed to bring the power of widgets to the all-new Lock Screen.

Alt text

Using WidgetKit, they brought some of watchOS Complications designs to widgets on the Lock Screen, including Circular, Rectangular, Inline Widgets.

Alt text

All of these widgets work on both iOS and watchOS because starting in watchOS 9, complications are also powered by WidgetKit. For the first time, you can use the same code to generate glanceable data on both platforms. WidgetKit manages platform differences for you automatically, using the appropriate system fonts by default, and tinting the widgets on the Lock Screen for maximum legibility.

Live Activities Widget Upcoming Support

Alt text

Live Activities makes it easier to stay on top of things that are happening in real time, right from the Lock Screen. Things like the latest score from a game, the progress of a ride share, or a workout, right on the Lock Screen, and always up-to-date. Just like with widgets, you create Live Activities with WidgetKit. The difference is, you update your Live Activity's presentation and state in real time.

Alt text

Since they're built with SwiftUI, you can even animate your updates from one state to the next. These updates make sure your Live Activities has the most current information when the user chooses to glance at it. Live Activities will be available starting in an update to iOS 16 later this year.

Messages Collaboration API

Alt text

With the new Messages Collaboration API, you can bring your app's existing collaboration experiences into Messages and FaceTime. When users share a link to content in your app, the API makes it easy for you to mark that link as collaborative, enabling a seamless experience. This works without compromising privacy. Messages identities and app identities remain private and are not shared.

Alt text

With one object, your users can initiate collaboration in two convenient ways that they're already familiar with. One, the Share Sheet, which has been updated to put collaboration front and center.

Alt text

And two, drag & drop, where you can share content you want to collaborate on by dragging it directly into the Messages conversation. And once the conversation is started, you can even post notices about content updates right to the Messages conversation.

Alt text

With a couple lines of code, your users can get back to collaborating in your app with a single tap in Messages. And with the collaboration popover, your users can get back to the conversation in Messages or FaceTime right from your app

App Intents Framework. Say Goodbye to Manual Add to Siri Button and Complex Intent Definition file for Custom Intent Shortcuts

Alt text

App Intents framework makes your app's features available to the system, so people can use them automatically through Siri and Shortcuts.

Alt text

Today, people have to add shortcuts manually before they can use them at all. Apple is making this automatic in iOS 16 with the new App Intents framework.

Alt text

App Intents is the next step for the SiriKit Intents framework that Apple introduced in iOS 10. If you adopt Intents to integrate with Widgets or domains like media or messaging, you should keep using the SiriKit Intents framework, but for developers who build custom intents for Siri and Shortcuts, you should go ahead and upgrade to App Intents.

Alt text

You can easily upgrade to App Intents in Xcode by pushing the Convert button in your intent definition file. Xcode will generate the equivalent App Intents source code, and then you fill in the blanks with your intent handling code.

Alt text

The App Intents framework is really easy to develop for because it's designed from the ground up for Swift, and it requires much less code. The Swift code that you write is the only source of truth, There's no separate intent definition files or code generation to keep in sync.

Passkeys

Alt text

Passkeys will streamline your authentication flows and address the top security issues with passwords. Passkeys were designed to be incredibly easy to use. The interface uses familiar Autofill-style UI and FaceID and TouchID for biometric verification.

Alt text

When setting up an account with a passkey, you don't need to create a password. Just type a user name and save the passkey to your iCloud Keychain. This will securely sync this passkey to all of your other Apple devices.

Alt text

Because passkeys are built on open industry standards that platforms are adopting, you can use the passkey you just created on your iPhone to sign into your app website on a Windows PC. On the website, just type your username, submit, and choose the option to sign in using a phone, scan the QR code, let the iPhone and PC securely connect, and you're signed in.

Alt text

When creating a passkey, the device generates a unique key that is specific to the website or app it was created for and protects it behind biometrics. It's impossible to have a weak passkey. It can't be forgotten, reused, or guessed. Passkeys are based on public key cryptography, which makes credential leaks from servers a thing of the past. Instead of storing salted, hashed passwords, that can leak and be cracked, your server keeps only a public key.

Alt text

Bringing passkeys to your app and website takes only a few steps. First, you'll teach your account backend to store public keys and issue authentication challenges. Then, on your website and in your app, you'll offer passkeys to users and adopt API to create a new passkey and sign in with it.

Passkeys are based on the Web Authentication, or WebAuthn, standard, which has been a collaborative effort across the industry from both platform vendors and service owners. The standard itself is mature and well documented.

iPadOS 16 UI Updates & DriverKit support

Alt text

With iPadOS 16, There's a seamless find-and-replace experience for UI text views that your apps get automatically, as well as updates to the navigation bar, toolbars, the document menu, that make it easy for your users to manage documents and customize their experience.

Alt text

To enable even more powerful applications of iPad with connected hardware, DriverKit comes to iPad, helping to unlock the incredible power of the M1 chip. It's the same API that's available on Mac today, enabling you to easily deliver support for your USB, audio, and PCI devices to an even larger audience.

watchOS 9 CallKit Framework & Bluetooth-Connected Medical Devices Robust Connectivity

Alt text

The CallKit framework in watchOS 9 includes a new Voiceover IP background mode that lets apps make voice calls directly from Apple Watch, with the same familiar user experience as FaceTime audio and phone calls.

Alt text
And Bluetooth-connected medical devices get more robust connectivity and data delivery, allowing for timely alerts when a critical condition is detected.

tvOS 16 Connected Experience

Alt text

tvOS 16 gives you new ways to create connected experiences between your apps on Apple TV and iPhone, iPad, or Apple Watch apps on nearby devices. So a workout could use motion data from Apple Watch, or you could use iPhone or iPad as a custom controller for your turn-based games, And tvOS manages device discovery and connection for you, so your app doesn't even need to be running on the other device. In fact, if your app isn't installed, the user is automatically prompted to download it right from the App Store.

AR and LIDAR Room Scanning with ScanKit and Room Plan

Alt text

Now, on iPhone and iPad, there are new cool features that use AR and LiDAR scanning with ScanKit and RoomPlan. These APIs let your apps create rich 3D parametric room models in USD and USDZ formats.

Alt text

So you can create a variety of workflows and experiences, from architecture and design, to retail and hospitality, and the models include furniture classification for categories such as sofas, cabinets, TVs, and yes, even kitchen sinks.

Metal 3 with Accelerated ML, Game Loading MetalIO API and, MetalFX Resolution Upscaling

Alt text

Metal 3, with powerful new features that help you render immersive graphics with even higher frame rates and enable new levels of computational performance. For instance, you'll get huge performance gains for the machine learning framework, PyTorch, which now uses the new Metal backend to enable ML training with the GPU.

Alt text

Metal 3 introduces fast resource loading with the Metal IO API that takes advantage of the Apple GPU's unified memory architecture to minimize loading overhead and ensures that the high-speed SSD storage that ships with every Apple silicon Mac has enough requests in its queues to maximize throughput. This new API provides faster and more consistent performance so that more time is spent drawing at the ideal quality.

Alt text

MetalFX upscaling helps you render immersive graphics in less time per frame. Here's how it works. Previously, you would render your full frame at native resolution, but the GPU render time might not hit the target frame time. Now, you can render the same complex scene at a lower resolution to meet the target frame times, and use MetalFX framework to perform temporal antialiasing and upscaling to the target resolution. This is a similar technology used by Nvidia DLSS and AMD FidelityFX.

MapKit Update & Apple Maps Server APIs

Alt text

MapKit 3D City Experience available to all developers in iOS 16. Users of your apps will be able to see incredible details, like 3D elevation, turn lanes, crosswalks and bike lanes, and amazing handcrafted 3D landmarks like the Golden Gate Bridge, or the Ferry Building.

Alt text

The additional detail of the map allows you to provide context and precision that was never before possible. You can, for example, show that a point of interest is between the crosswalk and where the bike lane starts.

Alt text

MapKit has powerful controls that allow us to position the camera in 3D space to create a precise view of the map. When adding an annotation or a route line sourced from MapKit's Directions API, MapKit automatically handles elevation and will adjust the annotation or route line by placing it on top of the 3D terrain. Animating the camera heading by adding a slow pan really brings the map view to life.

Alt text

In addition, Apple is also bringing another popular Apple Maps feature to MapKit, Look Around, which is a great way to explore the world at ground level, with high resolution 3D photography and smooth animations. Users can simply tap to move down the street.

Alt text

Maps Server APIs are RESTful and support four of the most used functions of MapKit: Geocode, which turns a lat/long into an address; Reverse Geocode, which does the opposite– it turns an address into GPS coordinates; Search; and Estimated Times of Arrival. Our new Maps Server APIs are a great way to make your own backend services richer and more performant. Of course, MapKit is built from the ground up on the same foundation of privacy as Apple Maps, and does not associate users' data with their identity or keep a history of where they've been.

WeatherKit

Alt text

WeatherKit is a native Swift API for all Apple platforms, and a REST API you can use from anywhere. These APIs deliver accurate, hyperlocal weather forecasts, to help your users stay safe, informed, and prepared.

Alt text

Apple are including 500,000 weather(for:location) API calls per month in your Apple Developer Program membership. Those of you who need more will be able to purchase additional tiers of service right in the developer app, starting this fall.

Live Text API VisionKit

Alt text

The Live Text API unlocks the ability to analyze image content, allowing users to interact with text and QR codes found in photos and paused video frames, and it provides quick actions so your users are just a tap away from taking action on relevant data.

Alt text

And the Data Scanner API unlocks the ability to analyze a live camera feed. It dramatically simplifies text and barcode ingestion for users. All you need to do is add any overlays or custom controls that tailor the live camera experience to the needs of your app. This is especially useful for consumer apps that rely on QR codes or enterprise apps built for back-of-warehouse inventory management, pick-and pack delivery services, and point of sale kiosks.

Both the Live Text and Data Scanner APIs support automatic detection of nine languages.

Conclusion

Alt text

There are so many new APIs and update to existing APIs that has been announced this year. And to understand them deeper, there are 175 sessions that we can watch to learn all of these amazing new SDKs.

That's it, let's keep on being a lifelong learner. Stay safe and healthy, have a great WWDC!

All the screenshoots in this article, Swift, SwiftUI, the Swift logo, Swift Playgrounds, Xcode, Xcode Cloud, iPhone, iPad, watchOS, tvOS, macOS, Safari, AppStore, TestFlight are trademarks of Apple Inc.

Summaries of each recap are referenced from transcript in Apple Official Developer App.