In-Depth into Persistence Frameworks

Core Data and SwiftData stand as pivotal persistence frameworks within the Apple ecosystem, forming a robust bastion for application data. For developers, mere familiarity with their usage is just the beginning. Delving deeper into the operating mechanisms and internal principles of these frameworks not only enhances understanding but also provides a significant edge in application development. This collection aims to unlock these deeper insights, offering a thorough exploration of the intricate workings behind these essential tools.

Core Data

  • Exploring CoreData - From Data Model Creation to Managed Object Instances

    This article will delve into the inner workings of Core Data in constructing managed object instances from a data model.

  • Mastering Relationships in Core Data: Fundamentals

    In the numerous discussions about Core Data, "object graph management" undoubtedly appears as a core concept. As a renowned framework for object graph management, Core Data's key task is how it precisely describes and effectively manages the complex relationships between different data instances. Indeed, the ability to manage relationships not only constitutes the core characteristic of Core Data but also represents a significant advantage over other data persistence frameworks. In this article, we will delve into the basic concepts of relationships in Core Data, while providing important guidance and suggestions for implementing these relationships.

  • Batch Operations in Core Data

    This article will introduce Core Data's batch operations, including their principles, usage methods, advanced techniques, and important considerations.

  • Several Tips on Core Data Concurrency Programming

    This article offers tips for Core Data concurrency programming, including debug params, reducing blocking , using perform, NSManagedObjectID and more.

  • Mastering Core Data Stack

    This article will explain how to design a Core Data Stack. It will cover the functions, components, and configurations.

  • Using Persistent History Tracking in CoreData

    This article provides an in-depth explanation of CoreData's Persistent History Tracking feature. It covers the complete process from responding, fetching, merging, to purging, and includes demonstration code for readers to utilize.

  • SwiftUI and Core Data: The Challenges

    Currently, my main challenge and research direction is how to integrate Core Data into popular application architectures, and make it work more smoothly in environments such as SwiftUI, TCA, Unit Tests, and Preview.

  • Core Data Reform: Achieving Elegant Concurrency Operations like SwiftData

    SwiftData, as the successor to Core Data, has introduced a multitude of innovative and modern design ideas. Despite its availability for some time now, many developers have yet to adopt it in their projects. This situation is partly due to SwiftData's higher requirements for the operating system version. Additionally, because SwiftData is not yet mature enough in some functionalities, developers might choose to continue using Core Data even if their operating system version meets SwiftData’s requirements. Can we integrate some of SwiftData's excellent design philosophies and ingenious implementations into the practical use of Core Data? This article aims to explore how to introduce elegant and safe concurrency operations similar to those of SwiftData into Core Data, implementing a Core Data version of @ModelActor.


  • Practical SwiftData: Building SwiftUI Applications with Modern Approaches

    In the previous article "Concurrent Programming in SwiftData", we delved into the innovative concurrent programming model proposed by SwiftData, including its principles, core operations, and related considerations. This elegant programming solution has earned considerable praise. However, as more developers attempt to use SwiftData in actual SwiftUI applications, they have encountered some challenges, especially after enabling Swift's strict concurrency checks. They found that SwiftData's actor-based concurrency model is difficult to integrate with traditional application construction methods. This article will explain, in a tutorial-like manner, how to integrate SwiftData with modern programming concepts smoothly into SwiftUI applications and provide strategies to address the current challenges faced by developers.

  • Unveiling the Data Modeling Principles of SwiftData

    This article will explore how SwiftData creates data models using code, the new language features it uses, and show how to create PersistentModel by declaring code.

  • Concurrent Programming in SwiftData

    As the successor to Core Data, SwiftData provides a more elegant and secure mechanism for concurrent programming. This article will introduce how SwiftData addresses these issues and offers developers a better experience with concurrent programming.

  • SwiftDataKit: Unleashing Advanced Core Data Features in SwiftData

    This article will discuss how developers can call the advanced features provided by Core Data in SwiftData without using the Core Data stack, in order to extend the current capabilities of SwiftData.

  • How to Observe Data Changes in SwiftData using Persistent History Tracking

    This article will explain how to observe specific data changes through Persistent History Tracking in SwiftData.

  • Relationships in SwiftData: Changes and Considerations

    In previous two articles, "Mastering Relationships in Core Data - Fundamentals" and "Mastering Relationships in Core Data - Practical Application", we explored in detail the concepts and techniques of relationships in Core Data. While much of this knowledge is also applicable to SwiftData, Core Data's successor, SwiftData introduces several significant changes in handling relationships. This article focuses on the changes that have occurred in the aspect of relationships within SwiftData, as well as the potential challenges and noteworthy details arising from these changes.

  • How to Handle Optional Values in SwiftData Predicates

    SwiftData has revamped the mechanism for creating data models, incorporating a type-safe mode for predicate creation based on model code. As a result, developers encounter numerous operations involving optional values when constructing predicates for SwiftData. This article will explore some techniques and considerations for handling optional values while building predicates.

  • Swift Predicate: Usage, Composition, and Considerations

    NSPredicate has always been a powerful tool provided by Apple, allowing developers to filter and evaluate data collections in a natural and efficient way by defining complex logical conditions. Over time, with the continuous maturation and development of the Swift language, in 2023, the Swift community undertook the task of reconstructing the Foundation framework using pure Swift language. In this significant update, a new Predicate feature based on Swift coding was introduced, marking a new stage in data processing and evaluation. This article aims to explore the usage, structure, and key considerations of Swift Predicate in practical development.

  • How to Dynamically Construct Complex Predicates for SwiftData

    NSCompoundPredicate allows developers to combine multiple NSPredicate objects into a single compound predicate. This mechanism is particularly suited for scenarios that require data filtering based on multiple criteria. However, in the new Foundation framework restructured with Swift, the direct functionality corresponding to NSCompoundPredicate is missing. This change poses a significant challenge for developers who wish to build applications using SwiftData. This article aims to explore how to dynamically construct complex predicates that meet the requirements of SwiftData, utilizing PredicateExpression, under the current technical conditions.