Core Data
Generated on 8/3/2024
4 searches
Core Data is a framework that has been traditionally used for data persistence in iOS applications. However, at WWDC 2024, Apple introduced significant updates and new features in SwiftData, which is designed to make data modeling and persistence easier and more efficient.
Key Points about SwiftData:
-
Introduction to SwiftData:
- SwiftData is a framework that allows you to model and persist your app's data across all of Apple's platforms. It leverages modern Swift language features like macros to write code that is fast, efficient, and safe (What’s new in SwiftData).
-
Core Data Integration:
- By default, SwiftData uses Core Data to store information. However, it also supports custom data stores, allowing you to use alternative backends like SQLite, remote web services, or JSON files (Platforms State of the Union).
-
Custom Data Stores:
- SwiftData now allows for fully custom data stores. This means you can create your own datastore with its own implementation to persist data across the container. For example, you can use a custom document format like JSON files (What’s new in SwiftData).
- The new Datastore protocol in SwiftData defines all the functionality needed for the store to be usable by the model context, including save, fetch, and caching (Create a custom data store with SwiftData).
-
History Tracking:
- SwiftData provides access to the history of changes in a datastore, which is useful for tracking local changes that need to be synced to a remote web service (Platforms State of the Union).
- For those using Core Data's persistent history, you can now migrate to SwiftData history instead (Track model changes with SwiftData history).
-
Schema and Query Enhancements:
- SwiftData introduces new macros like
#Unique
and#Index
to avoid duplicate models and optimize queries (What’s new in SwiftData). - The framework also supports complex filters and a new
#Expression
macro to improve performance (What’s new in SwiftData).
- SwiftData introduces new macros like
Relevant Sessions:
- What’s new in SwiftData
- Platforms State of the Union
- Create a custom data store with SwiftData
- Track model changes with SwiftData history
These updates make SwiftData a powerful and flexible framework for data persistence, building on the capabilities of Core Data while introducing new features and improvements.

Track model changes with SwiftData history
Reveal the history of your model’s changes with SwiftData! Use the history API to understand when data store changes occurred, and learn how to use this information to build features like remote server sync and out-of-process change handing in your app. We’ll also cover how you can build support for the history API into a custom data store.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

Create a custom data store with SwiftData
Combine the power of SwiftData’s expressive, declarative modeling API with your own persistence backend. Learn how to build a custom data store and explore how to progressively add persistence features in your app. To get the most out of this session, watch “Meet SwiftData” and “Model your schema with SwiftData” from WWDC23.

What’s new in SwiftData
SwiftData makes it easy to add persistence to your app with its expressive, declarative API. Learn about refinements to SwiftData, including compound uniqueness constraints, faster queries with #Index, queries in Xcode previews, and rich predicate expressions. Join us to explore how you can use all of these features to express richer models and improve performance in your app. To discover how to build a custom data store or use the history API in SwiftData, watch “Create a custom data store with SwiftData” and “Track model changes with SwiftData history”.