cookie store
Asked on 03/07/2025
1 search
It seems like you're interested in creating a custom data store, possibly for something like a cookie store, using SwiftData. At WWDC 2024, Apple introduced the concept of custom data stores in SwiftData, which allows developers to use any document, file format, or persistence backend of their choice. This feature is particularly useful for integrating SwiftData with existing systems or for using specific storage formats like JSON.
For more detailed guidance on creating a custom data store, you can refer to the session titled "Create a custom data store with SwiftData." This session covers the essentials of implementing a custom datastore, including how to use the new Datastore protocol to build a store that can read and write data in any format you choose.
If you're interested in the specific implementation details, you might want to check out the Example store chapter of the session "Create a custom data store with SwiftData" (07:42). This part of the session provides a practical example of implementing a store using a JSON file for persistence.
Relevant Sessions

A Swift Tour: Explore Swift’s features and design
Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.

Go further with Swift Testing
Learn how to write a sweet set of (test) suites using Swift Testing’s baked-in features. Discover how to take the building blocks further and use them to help expand tests to cover more scenarios, organize your tests across different suites, and optimize your tests to run in parallel.

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.