What’s new with swiftdata? Does it support deduplication with iCloud sync?
Generated on 7/31/2024
1 search
What's New with SwiftData
SwiftData has introduced several new features and improvements:
-
Schema Macro: A new schema macro allows you to construct compound constraints on persistent models. This includes the
unique
macro, which ensures that certain combinations of your model's properties remain unique, helping to avoid duplicates in your data. For example, in the Trips app, you can ensure trips are unique across their name, start date, and end date (What’s new in SwiftData). -
Custom Data Stores: SwiftData now supports custom data stores, allowing you to use alternative backends like SQLite, remote web services, or even collections of JSON files. This flexibility is achieved through the new datastore protocol (Create a custom data store with SwiftData).
-
History API: SwiftData history lets your app track modifications to its data, which is useful for features like syncing with a server or responding to changes from an app extension. This includes tracking transactions and changes, making it easier to manage data updates and deletions (Track model changes with SwiftData history).
Deduplication with iCloud Sync
Yes, SwiftData supports deduplication with iCloud sync. The unique
macro helps ensure that certain combinations of your model's properties remain unique, which can prevent duplicates when syncing data across devices. When two model instances share the same unique values, SwiftData performs an upsert on collision with an existing model, effectively managing duplicates (What’s new in SwiftData).
Relevant Sessions
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.
Platforms State of the Union
Discover the newest advancements on Apple platforms.
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.
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”.