Member-only story
Unveiling the Data Modeling Principles of SwiftData
While analyzing code, learning Swift’s new features

In the improvements of SwiftData, the ability to declare data models purely in code undoubtedly left a deep impression on Core Data developers. This article will delve into how SwiftData creates data models through code, its new language features, and demonstrate how to create PersistentModel
instances by declaring code.
Stay ahead with the latest updates and deep insights on Swift, SwiftUI, Core Data, and SwiftData. Subscribe to Fatbobman’s Swift Weekly to get exclusive articles, tips, and curated resources delivered straight to your inbox every week.
For even more valuable content and in-depth tutorials, visit my blog at fatbobman.com — your go-to destination for all things Swift and Apple development.
Three Facts
Understanding the following three facts is crucial for gaining a better grasp and comprehension of the modeling principles of SwiftData, as well as why SwiftData adopts the methods described in this article.
SwiftData is a framework built on top of Core Data
Although Apple rarely emphasizes the relationship between SwiftData and Core Data, it is undeniable that the SwiftData framework is built on top of Core Data. There are several benefits that Core Data brings to SwiftData:
- The database file format is compatible; existing data can be directly operated with the new framework.
- Inherits the stability verification of Core Data, significantly reducing potential issues.
Although SwiftData is based on Core Data, it does not mean that the same programming principles as Core Data must be used when developing with SwiftData. Since SwiftData combines many of the latest features of the Swift language, developers often need to use a fresh mindset to redesign data processing logic in many situations.