Apple SwiftData framework manages app data - IT SPARK Media

Apple SwiftData framework manages app data

[ad_1]

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.

Copyright © 2023 IDG Communications, Inc.

[ad_2]

Source link

x