DevPrep

All topics › Software architecture

MVVM

Middle PRO

The point

MVVM puts a mediator between View and Model — the ViewModel. It is an object with no UIKit/SwiftUI dependency that holds the screen state in a display-ready form (strings, isLoading flags, filtered lists) and exposes commands (load(), delete(id:)). The View observes the state and re-renders itself; the ViewModel knows nothing about the View — so several Views can show one ViewModel, and it can be tested without UI.

Data flow in iOS MVVM is mostly unidirectional: events go from the View to the ViewModel, state goes back. Two-way binding is used sparingly ($viewModel.query for a text field).

Observation mechanisms by era: KVO/RxSwift/ReactiveCocoa → Combine @Published + ObservableObject (iOS 13) → Observation @Observable (iOS 17) — SwiftUI tracks only the properties actually read in body and does not re-render more than needed.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store