Apple Introduces SwiftData
Written by Kay Ewbank   
Thursday, 15 June 2023

Apple has introduced the SwiftData framework as a way of making it easier to persist data using declarative code. The framework is integrated with SwiftUI and can be used to query and filter data using regular Swift code.

The framework was announced in a preview version at Apple's WWDC23 conference. Apple says the framework combines Core Data’s proven persistence technology and Swift’s modern concurrency features, and enables developers to add persistence to apps quickly, with minimal code and no external dependencies.


The data is modeled using regular Swift types with @Model, with no additional files or tools to manage. SwiftData can automatically infer many relationships and you can use clear declarations like @Attribute(.unique) to describe constraints.


By design, SwiftData supplements your existing model classes. The framework provides tools such as macros and property wrappers that can be used to describe your app’s schema in Swift code, removing any reliance on external dependencies such as model and migration mapping files.

Developers can describe the entire model layer (or object graph) for an app, and the framework handles storing the underlying model data, and optionally, syncing that data across multiple devices.

The SwiftData documentation says that the ability to preserve model data across launches is one of the benefits of SwiftData, as most apps define a number of custom types that model the data it creates or consumes, and SwiftData lets you persist that data so it’s available across app launches, and make use of the framework’s integration with SwiftUI to refetch that data and display it onscreen.

To let SwiftData save instances of a model class, a developer would import the framework and annotate that class with the Model macro. The macro updates the class with conformance to the PersistentModel protocol, which SwiftData uses to examine the class and generate an internal schema. Additionally, the macro enables change tracking for the class by adding conformance to the Observable protocol.

CloudKit syncing is supported. Data can be stored in files using DocumentGroup and synced via iCloud Drive, or you can use CloudKit to sync data between devices.

SwiftData is available in preview now.


More Information

SwiftData Documentation

Related Articles

Apple Releases Swift Playgrounds 4

Swift 5.5 Adds Concurrency Support

Swift 5.2 Improves Performance

Apple Launches Swift Playgrounds

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.


Eclipse JKube 1.16 Goes GA

Eclipse JKube makes deploying your Java application to a Kubernetes cluster a breeze. Let's find out what's new.

Angular and Wiz To Merge

Two web development frameworks used at Google are merging. One, Angular is open source and widely known, while the other, Wiz, is an internal web framework developed and used by Google for some o [ ... ]

More News

raspberry pi books



or email your comment to: