SwiftData

Persist your model with a single macro, and query it straight from SwiftUI.

Introduced
2023
WWDC23
Kind
Framework
Runs on
Get it from
iOS
17.0+
iPadOS
17.0+
Mac Catalyst
17.0+
macOS
14.0+
tvOS
17.0+
visionOS
1.0+
watchOS
10.0+
Works in Swift Playground ›
The trip list, kept in step with the store by @Query.

Overview

Add @Model to a Swift class and it becomes something you can save, fetch and sync. No separate schema file, no managed object subclasses.

In SwiftUI, @Query keeps a view in step with the store, and iCloud sync is a configuration option. Underneath it's built on the same proven storage as Core Data.

@Model

Turn a Swift class into a persistent model. The schema comes from your code.

@Query

Fetch, sort and filter right in a SwiftUI view, and stay in sync with the store.

ModelContainer

Configure storage once at the app level, including iCloud sync and migrations.

ModelContext

Insert, delete and save, with autosave and undo support built in.

Trip.swift
import SwiftData import SwiftUI @Model class Trip { var name: String var startDate: Date init(name: String, startDate: Date) { self.name = name self.startDate = startDate } } struct TripList: View { @Query(sort: \Trip.startDate) var trips: [Trip] var body: some View { List(trips) { Text($0.name) } } }

History

How it grew up.

2023

Introduced

Announced at WWDC23 as the Swift-native way to persist data.

2024

Indexes and custom stores

#Unique, #Index, history tracking and custom data stores.

2025

Model inheritance

Models can subclass other models.

2026

Sections and observers

Sectioned queries, Codable attributes and observers outside views.