Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2026 SwiftSwiftUI & UI FrameworksApp Services

WWDC26 · 13 min · Swift / SwiftUI & UI Frameworks / App Services

What’s new in SwiftData

Discover the latest enhancements to SwiftData. We’ll show you how to persist custom and third-party types using Codable, and group fetched data into sections in your SwiftUI app. We’ll also explore how to observe data store changes anywhere else using ResultsObserver and HistoryObserver, giving you the flexibility to drive powerful state objects and react precisely to model updates.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

  • 0:00 — Introduction
  • 0:53 — Sectioning your fetches
  • 2:56 — Using custom types
  • 6:26 — Observing data stores with ResultsObserver
  • 9:41 — Observing history with HistoryObserver
  • 12:20 — Next steps

Code shown on screen · 4 snippets

Sectioned fetching swift · at 0:01 ↗
// Sectioned fetching

struct TripListView: View {   
    @Query(sort: \Trip.startDate,
           sectionBy: \.destination)
    var trips: [Trip]

    var body: some View: {
        List(selection: $selection) {
            ForEach(_trips.sections) {section in
                Section(section.id) {
                    ForEach(trips) {trip in
                        TripListItem(trip: trip)
                    }
               }
            }
        }
    }
}
Using Codable swift · at 4:59 ↗
// Using Codable

import SwiftData

@Model class Trip {

    struct Location: Codable {
        var latitude: Double
        var longitude: Double
    }

    var name: String
    var destination: String

    var startDate: Date
    var endDate: Date

    var location: Location?
    @Attribute(.codable) var mapItemIdentifier: MKMapItem.Identifier?
}
// Use observation to update map bounds swift · at 8:20 ↗
// Use observation to update map bounds

@Observable @MainActor final class MapCameraController {
    private let resultsObserver: ResultsObserver<Trip, Never>
    var bounds: MapCameraBounds?
    private var token: ObservationTracking.Token?

    init(modelContext: ModelContext) throws {
        resultsObserver = try ResultsObserver<Trip, Never>(modelContext: modelContext)

        token = withContinuousObservation(options: [.didSet]) {[weak self], event in
            self?.bounds = self?.calculateBounds(trips: resultsObserver.results)
       }
    }

    private func calculateBounds(trips: [Trip]) -> MapCameraBounds? { / * */ }
}
// Using HistoryObserver to sync with a server swift · at 8:21 ↗
// Using HistoryObserver to sync with a server

@SyncActor final class ServerSync {
    private let observer: HistoryObserver
    private var token: ObservationTracking.Token?

    func start() throws {
        self.observer = try HistoryObserver(authors: ["App"], modelContainer: modelContainer)
        token = withContinuousObservation(options: .didSet) {[weak self] _ in
            _ = self?.observer.eventCounter
            self?.processChanges()
        }
    }

    private func processChanges() {
        // Fetch and process history transactions
    }
}

Resources