Any changes to swiftdata
Asked on 06/14/2025
1 search
In the "What's new in SwiftData" session at WWDC 2024, several changes to SwiftData were introduced:
-
Unique Macro: A new schema macro allows you to construct a compound constraint on persistent models. You can use the new unique macro to ensure that combinations of your model's properties remain unique. This helps in avoiding duplicates and performs an upsert on collision with an existing model. For example, in the Trips app, the unique macro ensures trips are unique across their name, start date, and end date. What’s new in SwiftData (00:02:43).
-
History API: SwiftData now includes a history API that allows your app to track modifications to its data over time. This can be useful for syncing with a server or responding to changes from an app extension. What’s new in SwiftData (00:03:37).
-
Custom Data Stores: SwiftData now supports custom data stores, allowing you to implement support for any persistence backend by changing the data store configuration. This opens up new possibilities for using different storage backends with SwiftData. What’s new in SwiftData (00:05:39).
These updates enhance the flexibility and functionality of SwiftData, making it easier to manage data persistence and model constraints in your applications.

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”.

SwiftData: Dive into inheritance and schema migration
Discover how to use class inheritance to model your data. Learn how to optimize queries and seamlessly migrate your app’s data to use inheritance. Explore subclassing for building model graphs, crafting efficient fetches and queries, and implementing robust schema migrations. Understand how to use Observable and persistent history for efficient change tracking.

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.