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
- Defining @Model Types
- The Model Container & Context
- Querying with @Query
- Inserting, Updating & Deleting