SwiftData is Apple's modern persistence framework for Swift, replacing the older, more verbose Core Data with a simpler, code-first approach built on Swift macros. It ranks #18 in trending tech at roughly 1.7% usage share. It's trending because it lets developers define data models as plain Swift classes annotated with @Model, with automatic SwiftUI integration via @Query โ removing most of the boilerplate that made Core Data notoriously painful to learn.
A SwiftData model is just a Swift class marked with @Model โ no separate schema file. SwiftUI views fetch it live with @Query.
import SwiftData
@Model
final class Task {
var title: String
var isDone: Bool
var createdAt: Date
init(title: String, isDone: Bool = false) {
self.title = title
self.isDone = isDone
self.createdAt = .now
}
}
struct TaskListView: View {
@Query(sort: \Task.createdAt) var tasks: [Task]
@Environment(\.modelContext) var context
var body: some View {
List(tasks) { task in
Text(task.title)
}
}
}
SwiftData ships built into Xcode โ no package to add. Create a new project and enable it in the App file.
1. Install Xcode 15+ from the Mac App Store
2. File > New > Project > choose the "App" template
3. In YourApp.swift, attach a model container:
.modelContainer(for: Task.self)
4. Mark your data classes with @Model and query them with @Query in views