肘子的 Swift 记事本

Impressions After WWDC 2021

Published on

Get weekly handpicked updates on Swift and SwiftUI!

WWDC 2021 has already ended a week ago. As always, Apple brought us new operating systems as well as a plethora of updates in terms of development tools, software architecture, and web services. Due to the pandemic, the WWDC events of the past two years have been pre-recorded, but the content seems to be delivered more precisely than before, and it’s more user-friendly for the viewers. This article will only introduce a few points from my personal interest and combine my experience of using these updates in the recent period.

Operating Systems

In recent years, Apple’s systems have been maintaining a gradual upgrade trend, and even with major version updates, they usually don’t bring particularly big surprises or changes. However, it is in these incremental changes that Apple has made the connections between its various systems even closer, and the ecosystem is becoming more and more complete. There are already a lot of articles about the new features of the system online, so I will just talk about a few of my own user experiences.

iOS 15 runs quite efficiently on older devices (I installed it on an iPhone 7). Compared to the iPhone, improvements in multitasking and multi-window interactions on the iPad are more noticeable. With subsequent software adaptations catching up, iPad apps may see a new surge. Monterey’s first version is noticeably more stable than last year’s Big Sur, and the consistency of the interface details is also good. Compared to last year’s major UI changes, this year’s UI is more about refinement and detail improvement. I haven’t tested watchOS 8 on a real device, but I’m quite interested in its new types of physical training and sleep respiratory rate monitoring.

Beyond the surface features, due to Apple’s significant improvements in the Swift language and system frameworks this year, I believe that apps adapted to new frameworks and services will perform very differently on new systems. Since most of the new features at the Swift language level and framework level this year will not be available on older operating systems, I guess Apple will continue to encourage users to upgrade. Fortunately, the new system covers a wide range of hardware and has similar hardware requirements to the systems of the past few years, so I expect the speed of system updates from users will be relatively quick.

Swift

Swift 5.5 is arguably the most significant update since the release of Swift 5.0. This year, Swift has restructured its solutions for asynchronous and multithreading, offering heavyweight features such as structured concurrency and actors.

Swift 5.5’s asynchronous and multithreading approaches are very friendly to developers. From recent use, it’s not only easy to get started with but also allows one’s code to benefit in a very short time. There is still some time before the official release of Swift 5.5, and besides the inevitable bugs, keywords and syntax are also constantly changing. The Swift Toolchain in Xcode 13 beta 1 has seen significant changes from the recent snapshots concerning asynchronous call syntax. Nevertheless, I still recommend that every Swift developer familiarize themselves with these new tools and modes as soon as possible, which can give them a fresh perspective on programming logic. I will write a few articles over the next period to introduce more about asynchronous and multithreading.

Another Swift enhancement that impressed me is the expanded lookup of static members in generic contexts. This seemingly minor change greatly improves the performance of autocomplete. The official framework has already fully adapted to this feature, and using Xcode 13, you’ll marvel at how useful autocomplete can be.

Compared to the first major feature, others such as #if expressions, localized lazy, property wrappers available for functions, enum conforming to Codable, Double—CGFloat conversion, etc., can only be said to be normal improvements.

SwiftUI

The overall feeling from learning and using it is to continue strengthening and standardizing.

If you just look at the Keynote, you might think that Apple has brought many new capabilities to SwiftUI, but a detailed analysis will reveal that most of them already have mature third-party solutions. Of course, the official solutions are indeed designed with better uniformity and are elegantly implemented, which will likely influence the authors of many third-party SwiftUI libraries. Let me mention a few improvements that personally struck me:

  • Comprehensive improvement of input. From Formatter bindings to the addition of focusedState, from onsubmit to submitLabel and keyboard placement in the Toolbar, the logic and design of input across all platforms have been delightfully enhanced. The official solution may not be the best on a single platform, but its cross-platform adaptability is indeed admirable.
  • Comprehensive introduction of asynchronous concepts. task and refreshable both provide contexts where asynchronous code can be directly executed. With the simplification of asynchronous programming in Swift 5.5, Apple will strongly guide developers to adopt asynchronous, multithreaded programming methods across various frameworks.
  • Enhanced rich text and symbols. Text can now directly use Markdown symbols, especially the new AttributedString, which lets developers customize Markdown symbols (with great results and high imaginative space). Text + AttributedString has addressed a significant shortcoming of rich text in SwiftUI. SF Symbols 3.0 has further increased the variety of symbols and added more rendering methods, reducing the design pressure for individual developers like myself. Other features such as dynamic text size restrictions and symbol variants are also quite distinctive.
  • The trend towards stylization is clear. Some work that previously required defining colors, sizes, and other steps has been unified into style. Material styles have also been added. Apple likes to use xxxStyle to define the style of various controls in SwiftUI, and thanks to the static member lookup capabilities of Swift 5.5, calling styles in code has become more convenient. This will also soon be reflected in third-party controls.
  • Comprehensive strengthening of lists. List, as a control with huge usage, has always had many shortcomings in SwiftUI. This update added many long-awaited functions, and the calling method is very SwiftUI-ized. ForEach can use bound data, searchable provides a search solution, swipeAction provides swipe buttons, etc., making many problems that used to only be solved by repackaging and data injection now directly solvable with the official solution. Additionally, it’s worth noting that you can finally remove dividers. The addition of Section provides more options for organizing data.
  • All-around improvement of buttons. This time SwiftUI provides excellent extensions for various types of Buttons, such as controlGroup presenting differently on various platforms, and through buttonStyle, controlSize, controlProminence, role:, etc., you can get official designer-level button styles with just a few lines of code. Menu also supports secondary menus, and for the Mac platform, a .button style has been added, etc. In short, the improvements in button presentation in this version are beyond what any third-party developer has achieved.
  • Greater compatibility with CoreData. @FetchRequest finally supports dynamic modification of sortDescriptors and predicates. Moreover, combined with the new @SectionedFetchRequest, it greatly enhances the list’s capabilities.
  • Other notable features include: Canvas, TimelineView, confirmationDialog, and many more new functions.

I will share more details about most of these features in future articles.

Regrettably, NavigationView did not receive any strengthening in this update.

Additionally, Demystify SwiftUI from this WWDC is a must-watch, as it helps developers understand SwiftUI’s development philosophy and core principles through detailed discussions on identity, lifecycle, and dependencies, and how to use them to ensure the accuracy and performance of applications.

CoreData + Cloudkit

There weren’t many changes to CoreData this year, mainly reflected in support for synchronization and multithreading. The SwiftData that was rumored and anticipated before this WWDC did not appear. However, Cloudkit still brought me a huge surprise this year: localized operation of shared databases.

In 2019, through NSPersistentCloudKitContainer, Apple connected CoreData with CloudKit’s private databases, and last year they localized the public databases, and this year they finally filled the last gap, making it easy for developers to implement real-time data sharing between app users and other iCloud users. To achieve this feature, CloudKit improved its synchronization mechanism with local data, and the response is not as sluggish as last year’s public database synchronization. Among the many new features at WWDC this year, Shared Data is the one I’ve been wanting the most!

Xcode

First of all, the most direct feeling is that many icons have become more refined than before. Xcode Cloud looks good, but it doesn’t have much attraction for an individual developer like me. If you are a Vim user, you will definitely be excited about the arrival of Vim mode. Version control has finally been improved, not only in functionality but even in the layout of the interface, which shows that Apple’s recognition of the importance of version control has improved. Thanks to the improvement of Swift, code completion and error prompts have made significant progress (in the beta version, error prompts are still a bit weird). Lastly, two features that are not entirely part of Xcode are worth special attention:

  • Integrated Swift Package Collections. Apple introduced Swift Package Collections this time, offering users a new choice for sharing and organizing third-party libraries. Xcode has fully integrated support for this.
  • Fully integrated DocC. I started touching Mac programming in 2019, and at that time, Apple’s documentation was not rich, but it has improved a lot in the past two years. When I first saw the official interactive tutorials for SwiftUI, I was quite shocked and hoped that there would be more similar documentation in the future. This year, Apple developed DocC, a new tool that builds beautiful, interactive, and native documentation directly from code. Using it, it’s easy to develop a set of documentation similar to Apple’s official documentation quality. Apple will open-source it within this year, and by then, even other platforms’ IDEs or other development languages will be able to use it for documentation work.

Others

WWDC covers too many areas, and I didn’t have time to watch and learn most of the sessions. In addition to the changes mentioned above, I paid extra attention to the changes in Foundation this year. Apple focused on AttributedString and Formatter. AttributedString is definitely the mainstay of rich text in the Apple development ecosystem going forward, and Formatter’s support for internationalization and localization has reached unprecedented heights. Additionally, considering that SwiftUI’s Text and TextField can now directly use Formatter, Apple will likely increase guidance for developers in its official frameworks in the future.

Resources for WWDC

Below are some resources I used to watch and study WWDC:

  • Developer (downloadable on both the Mac AppStore and iOS AppStore). I recommend using this app to watch videos, as you can click on the subtitles or code snippets of each session to quickly jump to the corresponding video segments.
  • WWDC Official Sample Code Here you can find the complete code for the demo projects mentioned in the videos.
  • WWDC NOTES Graphic and textual organization of each essential.
  • HackingWithSwift and his YouTube channel.
  • WWDC21Lounges QA summary.

I'm really looking forward to hearing your thoughts! Please Leave Your Comments Below to share your views and insights.

Fatbobman(东坡肘子)

I'm passionate about life and sharing knowledge. My blog focuses on Swift, SwiftUI, Core Data, and Swift Data. Follow my social media for the latest updates.

You can support me in the following ways