13.4 · SwiftData: models, contexts, predicates, actors and schema evolution

SwiftData is Core Data’s modern face: the same ideas (a context of objects, a store, migrations) with Swift macros and a SwiftUI-first API.

Mental model. You still have a container, a context per queue and a schema that must evolve. The macros remove the boilerplate, not the rules.

Using SwiftData

Models, the context, predicates and fetching.

  1. How do SwiftData’s @Model, ModelContainer, ModelContext, #Predicate and FetchDescriptor work together? 13.4.1 · L3
    A class marked @Model becomes persistent: the macro rewrites its stored properties so changes are tracked and observable (it also makes the class Observable…

Threads and versions

Model actors and versioned schemas.

  1. How do ModelActor, context-per-actor and VersionedSchema work in SwiftData, and what can you pass between actors? 13.4.2 · L5
    As with Core Data, a ModelContext is not Sendable and models are bound to their context, so the rule is one context per isolation domain. SwiftData supports…

More in Persistence & data