how can i do manual @Observable tracking
Asked on 2024-07-30
1 search
To manually track changes using @Observable in Swift, you can leverage the SwiftData history feature. This feature allows you to efficiently track changes in your data store over time. Here’s a brief overview of how you can do this:
-
Introduction to SwiftData History:
- SwiftData history lets your app query and process changes in the order they occurred each time your model is saved. It records a transaction containing metadata about all the changes.
- Transactions group together all changes that occurred in the data store on a boundary, such as a model context save. Each change represents a model that has been inserted, updated, or deleted.
-
Using SwiftData History:
- You can query the data in the store at any time. However, without history or manual diffing, there's no way to know from a query which models may have been added, deleted, or updated since a previous one.
- SwiftData history provides an easy and efficient way to track these changes. For example, you may want to have a time-ordered log of changes that occur when the app is offline. Later, these changes can be efficiently synced with a remote server.
For more detailed information, you can refer to the session Track model changes with SwiftData history.
Relevant Sessions
If you need more specific details or examples, please let me know!

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.

Create enhanced spatial computing experiences with ARKit
Learn how to create captivating immersive experiences with ARKit’s latest features. Explore ways to use room tracking and object tracking to further engage with your surroundings. We’ll also share how your app can react to changes in your environment’s lighting on this platform. Discover improvements in hand tracking and plane detection which can make your spatial experiences more intuitive.

What’s new in DockKit
Discover how intelligent tracking in DockKit allows for smoother transitions between subjects. We will cover what intelligent tracking is, how it uses an ML model to select and track subjects, and how you can use it in your app.
