0PricingLogin
SwiftUI Academy · Lesson

The Model Container & Context

Set up storage with modelContainer.

What a Container Is

The model container is the engine that sets up your storage on disk. Your whole app shares one container for all its SwiftData models.

Adding the Container

Attach a container to your app with the modelContainer modifier on a scene. One line gives every view access to your saved data.

WindowGroup {
    ContentView()
}
.modelContainer(for: Task.self)

All lessons in this course

  1. Defining @Model Types
  2. The Model Container & Context
  3. Querying with @Query
  4. Inserting, Updating & Deleting
← Back to SwiftUI Academy