Archive for June 17, 2022

Friday, June 17, 2022

Thoughts on SwiftUI After WWDC 2022

Casey Liss:

Dear Apple developers,

Buckle up, or get left behind.

💙,
Josh Shaffer

I’m super pleased that Apple has picked a direction, and is [slightly more consistently] pointing in a single direction.

However, even as someone who [mostly, on a good day] enjoys SwiftUI, this is probably writing a check that SwiftUI can’t quite cash.

I want to believe. Apple announced lots of changes that look great and seem to address common pain points. What’s less clear is whether the new stuff works as advertised and what the current feature and performance limitations are. From a Mac perspective, I sense that some problem areas are still outline views, focus, and large amounts of data.

In which ways is it safe to try SwiftUI because if it doesn’t work out you can easily revert that component to AppKit or UIKit? In which ways is that more risky because it affects the structure of the app such that it cannot easily be excised?

To me, the Cocoa-to-SwiftUI transition feels very different from the Classic-to-Cocoa transition because the first-party apps, especially for Mac, are not good examples to aspire to. It’s not clear to what extent this is due to the technology vs. design and QA choices that Apple is making. And it’s hard to tell what Apple itself thinks because its messaging style is to say that even early and obviously rough versions of new technologies like SwiftUI and Catalyst are ready for prime time and that the resulting apps are great.

Ideally, I would start using SwiftUI for new bits of UI that I add. Realistically, the new stuff requires macOS 13, which means it will be a long time before I can ship code that depends on it.

Steve Troughton-Smith:

Apple clearly underlined SwiftUI is future of 3rd-party dev on its platforms, and that UIKit & AppKit are to be lumped in with ObjC/Interface Builder as legacy tech. What Apple didn’t show is how it might get to that idyllic fantasy-SwiftUI from the painful reality it is today

Kyle Howells:

This is especially weird given how the “Build great desktop apps” stuff is all UIKit, and all the cool apps are being built are UIKit.

David Kopec:

It would help if they rewrote a major productivity app in it. Something more complex than preferences or widgets or weather. How about Mail or Pages or Final Cut Pro. I don’t think any of those are possible with the current state of SwiftUI. And hence the skepticism.

Steve Harris:

I’m actually horrified by how bad System Settings is, it should be a flagship UI experience. Also, if they want to announce that SwiftUI is the best way to make apps then they could at least demonstrate it. Using System Settings reminds me of Shortcuts on Mac, where maybe it looks OK at first then it feels so clunky and wrong, like it’s pretending to be a native app.

Steve Troughton-Smith:

So, developers, how is everybody feeling about this set of slides from WWDC’s SOTU, now you’ve had a week?

David Kopec:

After listening to Craig on The Talk Show, I realized they really mean “best way” (in their vision) not “only way going forward” which is how I originally read it between the lines. It’s clear UIKit and AppKit will be around for a long time.

Avi Drissman:

I heard exactly the opposite. Classic will be useful and a key technology for years, until it wasn’t. Carbon will be useful and a key technology for years, until it wasn’t. I heard an explicit statement that ObjC’s days are numbered.

Ken Kocienda:

My answer is from the perspective of a longtime member of the Apple community who has stopped developing for the platform. This set of slides confirms I won’t be going back.

Dimitri Bouniol:

Still seeing lots of people complain that despite Apple being very clear that SwiftUI is the future, they don’t think it’s good enough for them…

It is ready for production, you just need to use it enough to get comfortable with knowing when to fall back to App/UIKit.

[…]

But it also doesn’t fully replace App/UIKit (yet), so start using it incrementally when you can so you can gain that experience properly rather than rushing and failing when it’s too late.

Ilja A. Iwas:

So, are master-detail interfaces with multiple selection of 1,000 complex items loaded from a local database and bulk editing these items finally possible in Swift/SwiftUI 4? With reaction times < 1s? Or is Apple overselling again?

Paul Hudson:

I’d love to hear your feedback on where you think SwiftUI is after all these changes.

  • What are the most important missing features?
  • Which bits are still tricky to learn and/or do?
  • Are there parts where you still rely heavily on UIKit?

Damien Petrilli:

The joy of SwiftUI:

  • no issue on simulator
  • layout glitches on device

Exact same code

Luc Vandal:

In fact, all the SwiftUI improvements announced at #WWDC22 motivated me to resurrect a project I nearly shipped earlier this year but decided not to because of SwiftUI not being ready. Now’s the time!

Previously:

SwiftUI Changes at WWDC 2022

What’s new in SwiftUI:

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 the Layout 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:

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.

Use SwiftUI with AppKit:

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.

• • •

Majid Jabrayilov:

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.

Big Mountain Studio:

A list of everything new in SwiftUI after WWDC 2022.

Natalia Panferova:

SwiftUI has brand new navigation APIs in iOS 16 and macOS 13. They allow us to define stack-based navigation and multicolumn navigation.

Natalia Panferova:

NavigationSplitView accepts a columnVisibility 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.

Majid Jabrayilov:

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.

Kyle Macomber:

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.

Swift Talk:

We take a first look at SwiftUI’s new Layout protocol and integrate the flow layout we’ve built previously.

Natalia Panferova:

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.

Harlan Haskins:

Layout, Grid, and ViewThatFits obviate the need for the vast majority of GeometryReaders I’ve seen in the wild. Please give them a try, you won’t be disappointed!

Ish Abazz:

I kinda think that common layouts like EqualWidth, EqualHeight, and HorizontalFlow Layouts should be included in SwiftUI. We can build them ourselves with the new Layout protocol, but why have thousands of implementations of the same common layouts?

Joseph Heck:

Oh - this is so nice! ImageRenderer to take a SwiftUI view into either an Image or PDF context through CGContext.

Khoa Pham:

There are over 20 new #SwiftUI EnvironmentValues in iOS 16 #WWDC22 ranging from Controls Input, Widgets, Scrolling and SceneKit categories.

My favorites are requestReview and openWindow

Natalia Panferova:

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.

Natalia Panferova:

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.

Khoa Pham:

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

Javier:

I have categorized, curated, and in some cases commented the SwiftUI Digital Lounge questions.

Javier:

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:

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 or List in SwiftUI for macOS.

Swift 5.7 Announced

What’s new in Swift:

We’ll take you through performance improvements, explore more secure and extensible Swift packages, and share advancements in Swift concurrency. We’ll also introduce you to Swift Regex, better generics, and other tools built into the language to help you write more flexible & expressive code.

Embrace Swift generics:

Generics are a fundamental tool for writing abstract code in Swift. Learn how you can identify opportunities for abstraction as your code evolves, evaluate strategies for writing one piece of code with many behaviors, and discover language features in Swift 5.7 that can help you make generic code easier to write and understand.

Design protocol interfaces in Swift:

Learn how you can use Swift 5.7 to design advanced abstractions using protocols. We’ll show you how to use existential types, explore how you can separate implementation from interface with opaque result types, and share the same-type requirements that can help you identify and guarantee relationships between concrete types

Meet distributed actors in Swift:

Discover distributed actors — an extension of Swift’s actor model that simplifies development of distributed systems. We’ll explore how distributed actor isolation and location transparency can help you avoid the accidental complexity of networking, serialization, and other transport concerns when working with distributed apps and systems.

Visualize and optimize Swift concurrency:

Learn how you can optimize your app with the Swift Concurrency template in Instruments. We’ll discuss common performance issues and show you how to use Instruments to find and resolve these problems. Learn how you can keep your UI responsive, maximize parallel performance, and analyze Swift concurrency activity within your app.

Eliminate data races using Swift Concurrency:

Join us as we explore one of the core concepts in Swift concurrency: isolation of tasks and actors. We’ll take you through Swift’s approach to eliminating data races and its effect on app architecture. We’ll also discuss the importance of atomicity in your code, share the nuances of Sendable checking to maintain isolation, and revisit assumptions about ordering work in a concurrent system.

Meet Swift Async Algorithms:

Discover the latest open source Swift package from Apple: Swift Async Algorithms. We’ll explore algorithms from this package that you can use with AsyncSequence, including zip, merge, and throttle. Follow along with us as we use these algorithms to build a great messaging app. We’ll also share best practices for combining multiple AsyncSequences and using the Swift Clock type to work with values over time.

• • •

Slava Pestov:

Xcode 14 ships with Swift 5.7, which brings massive improvements to generics and protocols! 🧵

John Sundell:

Swift 5.7 introduces a new, more concise way to unwrap optional values using if let and guard let statements.

Donny Wals:

While it sounds like the any keyword acts as a type erasing helper, all it really does is inform the compiler that you opt-in to using an existential (a box type that conforms to a protocol) as your type.

Donny Wals:

In Swift 5.7, protocols can specify primary associated types. These associated types are a lot like generics. They allow developers to specify the type for a given associated type as a generic constraint.

John Sundell:

Thankfully, this is a problem that Swift 5.7 neatly solves by expanding the some keyword (that was introduced back in Swift 5.1) to also be applicable to function arguments.

[…]

Swift 5.7 once again introduces a much more lightweight way to express the above kind of declaration, which works the exact same way as when specializing a concrete generic type (such as Array<Article>). That is, we now can simply tell the compiler what Element type that we’d like our input Collection to contain by adding that type within angle brackets right after the protocol name[…]

Marcin Krzyzanowski:

“Any UIKit subclass that uses deinit now essentially causes warnings in Swift 5.7 while they are never touched on other threads anyways.”

Karoy Lorentey:

(Set now uses the new Temporary Buffers feature to make operations like intersect up to 4-6x faster.

Previously:

Update (2022-07-06): Matthaus Woolard and Natalia Panferova:

This post highlights some of the Swift updates that caught our attention this WWDC.

iCloud Shared Photo Library

Benjamin Mayo:

As Apple presented it, it seemed like the shared library would be tied to the Family Sharing system; the six users are the six people in your Family Sharing group. That would certainly be the Occam’s razor approach, removing the need for additional account management steps. However, apparently, that is not the case and the “up to six users” can include people that aren’t in your Family Sharing circle. That definitely opens up the feature to be useful to groups of people who want to share their photos but are not neatly contained into a single household, with just one shared payment method between them. It does raise some finicky questions, though, like how exactly does iCloud allocate the shared library’s storage. If someone contributes a photo, does the file size count against their personal iCloud storage quota, the person who created the shared library originally, or a wholly separate bucket altogether? Who pays for it, if you need more space? Who is in control of adding and removing people? Can you be removed from the shared library against your will, and if that happens, can you get a local copy of all the pictures of you before you lose access?

Previously:

Update (2022-07-07): Benjamin Mayo:

The old Photos shared albums are worse in every way but one: they were more social. The new Shared Library has no way for individuals to like or comment on pics.

In fact, if you heart a pic in the Shared Library, it hearts it for everyone … which feels a bit silly.