Making Swift Stronger, Keeping It Simple

Fatbobman's Swift Weekly #062

Dec 16, 2024

Two years ago, a friend asked me for a programming language recommendation for his six-year-old who was showing interest in coding. Considering he already had an iPad and MacBook, I didn't hesitate to...

Dec 18, 2024
Traps and Countermeasures for Abnormal onAppear Calls in SwiftUI

onAppear is an extremely crucial lifecycle method in SwiftUI, used to inject key logic when a view is presented. Since view instances may be created and rebuilt frequently, developers often choose to prepare data and perform initialization operations within these methods. In theory, the timing of these lifecycle method calls should be predictable and consistent. However, in certain specific scenarios, onAppear may be called unexpectedly and unnecessarily. This not only can lead to performance overhead but also may cause uncontrollable changes in the application's state. This article will uncover this easily overlooked SwiftUI behavior trap and provide temporary countermeasures.

Model Inheritance in Core Data

One of Core Data's outstanding features is its ability to allow developers to declare data models in a manner closer to object-oriented programming without worrying about the underlying storage implementation details. Within this framework, model inheritance is a particularly important mechanism. This article delves into the core concepts of model inheritance, including Parent Entity, Sub Entity, and Abstract Entity. We will analyze their advantages and disadvantages and explore how to achieve similar effects without directly using these features.

Dec 4, 2024
Typefully: Say Goodbye to the Hassles of Social Media Posting

As social media channels continue to expand, internet users often find themselves managing multiple social accounts without even realizing it. For content creators and corporate account managers, the preparatory work required to post content across various social platforms is becoming increasingly cumbersome. Over the past month, I started using Typefully to centrally manage and publish content on multiple social platforms. Now, I'd like to share my experience.

Nov 27, 2024
Intentional Design or Technical Flaw? The Anomaly of onChange in SwiftUI Multi-Layer Navigation

SwiftUI provides the onChange modifier, allowing developers to listen for changes in specific values within a view and execute corresponding actions when those values change. Intuitively, as long as a view is part of the currently visible branch of the view tree (active), the corresponding closure should be triggered when the observed value changes. However, in certain navigation scenarios, the onChange modifier seems to become "selectively deaf," inexplicably remaining silent even when the observed value changes. Is this a carefully designed feature by Apple, or a long-hidden code defect? This article aims to unveil this phenomenon and provide necessary caution to developers.

Using Transactions Instead of Save in SwiftData and Core Data

Ensuring data consistency and integrity is crucial in data persistence operations. The SwiftData framework introduces the `transaction` method in `ModelContext`, providing developers with a more elegant way to organize and manage data operations. This article explores how to use the concept of transactions to build more reliable and efficient persistence operations.

Nov 13, 2024
Understanding SwiftUI's View Update Mechanism: Starting from a TimelineView Update Issue

In SwiftUI, the automatic view update mechanism allows us to easily build responsive user interfaces. However, sometimes views may not update as we expect. This article explores SwiftUI's view update mechanism through a seemingly simple but representative TimelineView update issue.

Mastering Data Tracking and Notifications in Core Data and SwiftData

Core Data and SwiftData, as powerful persistence frameworks in the Apple ecosystem, not only provide declarative data listening tools like @FetchRequest and @Query, but also have a complete set of data tracking and notification mechanisms built-in. Understanding and mastering these mechanisms is crucial for building robust data-driven applications. This article will take you through multi-layered solutions—from simple custom notifications to the powerful Persistent History Tracking and SwiftData History—to help you handle various complex data synchronization scenarios.

Starting with Project Refactoring: Sharing Five Swift Modules

Recently, I embarked on the reconstruction of an app that had not received significant updates for four years. During the process, I extracted some functional modules and shared them as open-source projects. This article provides a brief introduction to the libraries I have open-sourced over the past two months.

Weekly Swift & SwiftUI insights, delivered every Monday night. Join developers worldwide.
Easy unsubscribe, zero spam guaranteed