Paul Krill
Editor at Large

Apple SwiftData framework manages app data

news
Jun 7, 20232 mins

The platform allows developers to add persistence and concurrency capabilities to apps.

Apple’s SwiftData, a persistence framework built for the company’s Swift language, was introduced this week as a mechanism for managing data within apps.

Now in beta, SwiftData purports to combine Core Data’s persistence technology with Swift concurrency capabilities. A framework is provided for data modeling and management. Similar to the SwiftUI user interface development tool, SwiftData focuses on code with no external file formats. The Swift macro system is used to create a seamless API experience.

With SwiftData, persistence can be quickly added to apps, with no external dependencies and minimal code, according to documentation. SwiftData enables writing code that is fast and safe; developers are able to describe the model layer or object graph for an app. The framework stores underlying model data and, if desired, syncs that data across different devices.

Beyond persisting locally created content, an app that fetches data from a remote web service could, for example, use SwiftData to implement lightweight caching and offer limited offline functionality. SwiftData is intended to make it easy to persist data using declarative code. Developers can query and filter data using regular Swift code and then integrate with SwiftUI. Data can be modeled using regular Swift types with @Model, with no additional tools or files to manage. Relationships can be automatically inferred.

Positioned as being unintrusive by design, SwiftData supplements an app’s existing model classes. Developers can attach the Model macro to any model class to make it persistable. Model property behavior can be customized, while the ModelContext class can insert, update, and delete instances of the model and write unsaved changes to disk. To display models in a SwiftUI view, developers can use the Query property manager. As an app’s model layer evolves, SwiftData performs automatic migrations of the underlying model data, providing a consistent state. To provide automatic iCloud sync, SwiftData requires the CloudKit entitlement and iCloud container.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author