0Pricing
Swift Academy · Lesson

The MVVM Pattern

Separate view, view model, and model concerns.

What Is MVVM?

MVVM stands for Model-View-ViewModel. It is an architectural pattern that separates your app into three layers, each with a single clear responsibility.

  • Model — data and business rules
  • View — what the user sees
  • ViewModel — the bridge that prepares Model data for the View

The goal is separation of concerns: each layer changes for its own reason, independently of the others.

The Model Layer

The Model holds your raw data and the rules that govern it. It knows nothing about the screen or how things are displayed.

Models are usually plain structs or domain objects. They are easy to test because they have no UI dependencies.

struct User {
    let id: UUID
    let firstName: String
    let lastName: String
    let isPremium: Bool
}

struct Order {
    let items: [String]
    let total: Decimal
}

All lessons in this course

  1. The MVVM Pattern
  2. Binding View Models to Views
  3. The Coordinator Pattern
  4. Testing View Models
← Back to Swift Academy