๐Ÿ“ฑ

SwiftData

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.

Quick facts
Type: Persistence / data-modeling framework
Made by: Apple
License: Proprietary (part of Swift/Xcode toolchain)
Language/Platform: Swift; iOS, macOS, watchOS, visionOS
Primary use case: Local on-device data persistence for SwiftUI apps
Jump to: ExampleGetting startedBest for

Example

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)
        }
    }
}

Getting started

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
Best for: New SwiftUI apps on Apple platforms that need local, on-device persistence โ€” to-do lists, notes, offline caches โ€” without the ceremony of setting up Core Data's .xcdatamodeld files.