0Pricing
SwiftUI Academy · Lesson

Dependency Injection for ViewModels

Inject services to keep view models testable.

The Hidden Dependency Problem

If a ViewModel creates its own network client inside itself, tests are stuck hitting the real server. That tight coupling makes it hard to swap later.

Inject Instead of Create

Dependency injection means passing in what a ViewModel needs from outside, rather than letting it build those services itself.

All lessons in this course

  1. Why MVVM Fits SwiftUI
  2. Designing a ViewModel
  3. Binding Views to ViewModels
  4. Dependency Injection for ViewModels
← Back to SwiftUI Academy