Daily iOS
Persistence

SwiftData building blocks

Say you're building a to-do app with SwiftData. What do @Model, ModelContainer, ModelContext, and @Query each do?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A @Model class is the schema, ModelContainer is the store, ModelContext is the unit of change (insert, delete, save), and @Query is a fetch that keeps the view up to date.

Share a question