0Pricing
SwiftUI Academy · Lesson

Inserting, Updating & Deleting

Mutate the store and reflect changes live.

Changing Your Data

Now you will change the store: add new records, edit existing ones, and remove what you no longer need. ✏️

Inserting a Record

Create an object and call insert on the context to add it. SwiftData starts tracking it for saving right away.

let task = Task(title: "Walk dog")
context.insert(task)

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