Mastering SwiftUI 2.0

This is the manuscript of an unpublished book on the use of SwiftUI v2.0, dating from early 2020. Six years later, I am providing it here as a historical artifact. It reflects the state of SwiftUI at the time (including early assumptions, terminology, and APIs), and is presented largely as-is.

Way back in the dim and distant past of 2019, I wrote a book on SwiftUI titled ‘Mastering SwiftUI,’ to be published by Pragmatic Programmers, and ably edited by Tammy Coron. Late in the year I updated it with new SwiftUI 2.0 features like support for trackpad-driven iPadOS apps, and for use with the then-new drag and drop support. In early 2020 I returned to work at Apple, and the (essentially complete) book wound up not being published due to potential conflicts of interest.

If you dig around on the Apple Developer Forums then you’ll eventually run into a whole host of replies I made in 2019 and 2020, while I was writing this book, and which rather informed a lot of what I decided to cover, for example:

Not everything here made it directly into the finished book, though pretty much everything I learned by trying to solve problems on the forums led to some sort of changes within the book’s content.

Since the book was never published, I got to keep everything I wrote, and now it’s been almost six years, and five major versions of SwiftUI have gone by. I’ve thus made the decision to post the whole thing here for the sake of posterity. One point I’d like to make in particular is that the some of the charges leveled at early SwiftUI releases—specifically that it wasn’t possible to write ‘real’ apps without doing most of the work in UIKit—were actually quite overblown. Outside of a few specific views and some occasional ScrollView shenanigans (which to be fair took many years to resolve adequately), I was able to do pretty much everything I needed to build an Apple-styled application nicely. I even had a macOS version running on the side from the same code, and had begun watchOS and tvOS as well, though those chapters were ultimately dropped.

A lot of the general information is still somewhat valid, like the discussion of state, bindings, the environment and preferences. Other pieces are less so, as much of the UI (and a lot of the custom pieces we build throughout the book) have been superseded. We how have SwiftData, @Observable, custom layouts, and many more interesting things.

Some pieces you might find interesting:

So: consider this an interesting historical curio, and maybe mine it for those insights that still apply today.


© 2009-2019. All rights reserved.

Powered by Hydejack v9.2.1