When people reunite after a long absence, they are often surprised by the changes in each other; however, the transformations in those who are with us day after day are often overlooked. In this article, I will sift through the key updates to SwiftUI that have made a significant impression on me since its first version. This is not only a reflection on the evolution of SwiftUI from its inception to its maturity but also a fresh appreciation of the vitality it embodies.
Each update to SwiftUI has brought numerous new features and capabilities. In this text, I will focus primarily on those changes that have had a profound impact on me personally and discuss other frameworks and features closely related to SwiftUI and the Apple ecosystem, demonstrating how they collectively shape the platform we use today.
Don’t miss out on the latest updates and excellent articles about Swift, SwiftUI, Core Data, and SwiftData. Subscribe to Fatbobman’s Swift Weekly and receive weekly insights and valuable content directly to your inbox.
2019
Despite its initially limited functionality, the first version of SwiftUI showcased some core features—such as its declarative syntax, reactive mechanisms, and layout logic—that have persisted through today with almost no changes across multiple versions. This not only proves the thoughtful consideration Apple gave when designing SwiftUI but also highlights the forward-thinking nature of its philosophy and architectural design.
The framework's name itself illustrates the inseparable connection between SwiftUI and the Swift programming language, a relationship that has been continually strengthened and validated with each subsequent update. SwiftUI leverages the features and advantages of Swift, and conversely, the development of Swift has also been influenced to some extent by the evolution of the SwiftUI framework.
Released alongside SwiftUI was the Combine framework, which provides powerful control over asynchronous data streams. SwiftUI uses it to implement an observation mechanism for reference types. Combine has enabled Apple and third-party developers to conveniently transform existing APIs into reactive APIs that support SwiftUI. However, due to Combine's inability to offer high-precision observation capabilities, SwiftUI faced significant performance issues in certain scenarios, which were not addressed until the introduction of the Observation framework last year.
Also launched at WWDC 2019 was Core Data with CloudKit, giving new life to Core Data and offering a unique and powerful advantage for applications within the Apple ecosystem. Many developers have embraced Core Data, largely attracted by its convenient and free data synchronization capabilities.
Although the initial version of SwiftUI may seem naive from today's perspective, as a declarative and reactive framework introduced by Apple, it has fully demonstrated its uniqueness and potential.
2020
-
New Project Templates: Xcode introduced new project templates for SwiftUI, allowing developers to more easily create complete app entries using the
App
andScene
protocols. Additionally, this update brought SwiftUI support for macOS development and introduced multi-window capabilities on iPad. -
Numerous New Lazy Containers: This version introduced a variety of lazy containers such as
LazyVStack
,LazyHStack
,LazyVGrid
, andLazyHGrid
. These containers offer more flexible layout options and are natively implemented in SwiftUI, independent of any specific UIKit/AppKit components. Unfortunately, these native lazy containers still have some performance issues, and many developers are eager for the development team to resolve these soon. -
@StateObject: The introduction of
@StateObject
addressed the instability issues with the lifecycle of reference type instances that were previously observed with@ObservedObject
. -
onChange: The
onChange
modifier enhances developers' ability to execute logic in response to specific state changes within views, further reinforcing SwiftUI's unique take on declarative programming. This includes embedding some lightweight imperative logic directly into the function-based UI declarations. Although this design philosophy has its pros and cons, it also provides unique advantages to SwiftUI. -
Scrolling Positioning:
ScrollViewReader
offers a method for positioning within scroll views usingid
andanchor
, fully reflecting SwiftUI’s philosophy of layout: based on view identity and not reliant on absolute positioning. - Introduction of Widgets: Starting with iOS 14, Apple introduced WidgetKit, a framework specifically designed for building widgets. WidgetKit requires developers to use SwiftUI to construct these widgets, a change that significantly encouraged developers who were initially hesitant about adopting SwiftUI to begin actively learning and using it.
At WWDC 2020, Core Data with CloudKit introduced synchronization features for public databases, further expanding its potential for data management and multi-device synchronization.
Following WWDC 2020, SwiftUI now has the fundamental capabilities needed to build a complete application. In less complex application scenarios, developers can almost avoid using UIViewRepresentable
to wrap UIKit components.
2021
-
Integration of the new concurrency model: With the release of Swift 5.5, a new concurrency model was introduced to Swift. SwiftUI leverages the
task
,task(id:)
, andrefreshable
modifiers to provide a convenient context for this new concurrent code, significantly simplifying the complexity of asynchronous programming. -
Focus management based on view hierarchy: With
@FocuseState
, SwiftUI not only completed the previously missing text input focus management features but also elevated focus management to a new level. Developers can now manage multiple focus transitions and detect focus states across the entire view hierarchy. This unified focus management feature left a profound impression on me as it not only fulfills basic functionalities but also provides an optimal solution in line with the philosophy of SwiftUI. -
Integration of FormatStyle: With the introduction of new Formatter APIs by Swift's Foundation, SwiftUI has supported these formatting interfaces in
Text
andTextField
components. This allows developers to control the formatted input and output of text more conveniently throughFormatStyle
, greatly enhancing the expressiveness and readability of the code. However, there is currently a limitation in usingFormatStyle
inTextField
: it cannot apply formatters in real-time during user input. This is an area where SwiftUI needs to improve in future versions. -
Support for AttributedString: The support for
AttributedString
in SwiftUI significantly enhanced the functionality and flexibility of theText
component for displaying text. This change provides developers with a more diverse range of text processing options, greatly enriching the user interface's expressiveness. However, despite the significant enhancements brought byAttributedString
, there have been no similar-scale features introduced since its inclusion. More regrettably,TextField
andTextEditor
still do not supportAttributedString
to this day, limiting these controls' ability to handle complex text formats. -
Dynamic modification of fetch conditions: This update introduced the ability to dynamically adjust fetch conditions in
@FetchRequest
, allowing developers to modify conditions without needing to create additional wrapper views. However, the@Query
property wrapper introduced for SwiftData in 2023 does not yet have this capability.
At WWDC 2021, Core Data with CloudKit introduced data sharing capabilities, completing the three major features of Core Data with CloudKit.
It can be said that in 2021, the many enhancements SwiftUI received were closely related to the updates of Swift and Swift Foundation that year.
2022
-
Layout Protocol: The introduction of the
Layout
protocol not only provided developers with the ability to create custom layout containers but also deeply demonstrated SwiftUI's layout mechanism based on negotiation. This protocol has enhanced developers' understanding of SwiftUI's layout logic. The newGrid
component, as well as existing layout components such asVStack
andHStack
, have been updated to conform to theLayout
protocol and supportAnyLayout
, significantly increasing layout flexibility. Currently, theLayout
protocol does not support the creation of lazy containers; we look forward to future versions expanding and refining this capability. -
New Programmatic Navigation:
NavigationStack
andNavigationSplitView
introduced a new programmable navigation system, fundamentally improving previous limitations with SwiftUI navigation. This change has led many developers to set the minimum system requirements for SwiftUI projects to iOS 16 to utilize these new navigation features. - Swift Charts: Apple's introduction of the Swift Charts framework for SwiftUI has set new standards in the industry for construction methods, visual effects, and integration with SwiftUI. In its second-year update, the framework added more chart types and support for interaction, further extending its functionality. Swift Charts has now become a top choice for chart applications within the Apple ecosystem, enhancing the significance and practicality of SwiftUI itself.
-
Enhanced macOS Support: This version significantly improved support for macOS, particularly in handling
WindowGroup
as well asSettings
andMenuBarExtra
. From this version onward, SwiftUI's capabilities in building macOS applications have been substantially enhanced.
The updates in 2022 brought many significant improvements to SwiftUI, especially the Layout
protocol and the new navigation system, which have profound implications for the future development of SwiftUI applications.
2023
-
New Observation Framework: With the release of Swift 5.9, the newly introduced Observation framework provides the ability to observe properties of observable objects, fundamentally solving the issue of excessive invalid updates in SwiftUI views caused by insufficient precision in Combine observations. The full adoption of Observation has significantly improved application efficiency. Moreover, this update has simplified the declaration and injection of state in SwiftUI; developers can now manage various states simply using
@State
andEnvironment
, without relying on Combine. -
Revolutionary Upgrades in Animation and Visual Effects: The 2023 update brought a range of innovative features to SwiftUI, including animation completion callbacks, phase animations, keyframe animations, and new Transition and Shape protocols, along with support for Shaders. These features have significantly enhanced developers' freedom in creating animations and visual effects. The newly introduced
animation
andvisualEffect
modifiers use closures to provide clearer logic handling, effectively reducing the impact on upstream and downstream components of the view tree, guiding the future development of SwiftUI view decorators. -
Comprehensive Enhancement of Scrollable Containers: Scrollable containers have also been enhanced with many new features, such as scroll indicators, margin adjustments, scroll clipping, and advanced scrolling capabilities independent of
ScrollViewReader
. Although these individual features might not seem prominent, their collective appearance certainly sparks speculation: could this be laying the groundwork for a major update to lazy container functionalities in the future? -
SwiftData: The long-awaited SwiftData was finally released, serving as the successor to Core Data. Its code-based modeling approach and tight integration with the Observation framework make it the most suitable data management framework for the SwiftUI era. If the upcoming WWDC 2024 still does not introduce a feature similar to
NSFetchedResultsController
for external data retrieval (real-time change detection) in SwiftData, it will further confirm Apple's strategic decision to position SwiftUI as the sole UI framework for the future, accelerating this transition. - visionOS: With the launch of Apple Vision Pro, it has become the only hardware platform in the Apple ecosystem where native application development exclusively supports SwiftUI. This change indicates that the Apple Vision Pro team will use SwiftUI to build more native applications, a development eagerly anticipated by developers. The widespread adoption of SwiftUI by Apple's official team will promote rapid iteration in fixing issues, enhancing performance, and introducing new features in the framework. I look forward to seeing more official applications developed using SwiftUI on iOS and macOS platforms at this year's WWDC 2024.
2023 has become a pivotal year in the development of SwiftUI, with the introduction of the Observation framework and SwiftData, among other innovative technologies, helping to cement its status as a mainstream development platform.
Looking Ahead to WWDC 2024
In an era where AI becomes a mainstream trend, how will SwiftUI leverage the powerful momentum of AI to achieve breakthrough improvements? At the upcoming WWDC 2024, which will be held in two weeks, I believe we will witness more exciting transformations.
Let's all look forward to the surprises that WWDC 2024 will bring!
The original article was published on my blog Fatbobman's Blog.
Top comments (1)
Good post.