3 of 22 · UI patterns
MVP (Passive View)
MVP (Model–View–Presenter) makes the view passive: it forwards events and executes display commands, while a Presenter holds all presentation logic and talks to the view through a protocol.
How it's wired
- View ↔ Presenter through a protocol (MVPNoteView).
- The presenter pushes commands like setSaveEnabled into the view.
| Part | Owns | Looks like |
|---|---|---|
| View | Forward events, execute display commands | UIViewController: NoteView protocol |
| Presenter | Decide what to show, hold weak view | Plain class, no UIKit |
| Model | Domain data, rules, services | Structs, services |
Where MVP breaks down
- The view protocol grows with every label: setTitle, setSaveEnabled, showError, showSpinner. A 40-method view protocol is a sign the screen should be split.
- Commands drift from state. The presenter pushes deltas, so there's no single snapshot of what the screen shows. Rotation, restoration or cell reuse means replaying commands correctly. MVVM's state-based binding avoids this class of bug.
- Lifecycle bleeds in. Presenters start mirroring viewDidLoad and viewWillAppear. Keep those calls few and named by intent (screenDidAppear, retryTapped).
When I'd use MVP
| UIKit codebase, no reactive layer | MVP gives testable presenters with zero framework. |
|---|---|
| SwiftUI or @Observable available | MVVM. State binding beats command replay. |
Compared
MVP vs MVVM
MVP
ViewPresenterModel
Presenter pushes commands into a passive view.
MVVM
ViewViewModelModel
View binds to state the ViewModel exposes.
| MVP | MVVM | |
|---|---|---|
| Talks to the view via | Commands through a protocol | State the view observes |
| Screen's source of truth | Spread across commands | ViewModel state |
| Testing | Fake view records calls | Assert on state |
| Fits | UIKit, no binding framework | SwiftUI, @Observable, Combine |
Expert notes
- The crisp distinction interviewers want: MVP pushes commands, MVVM exposes state. Everything else follows from that.
Check yourself
Answer out loud before you reveal. Recall is what makes it stick.
Explain MVP (Passive View) in 30 seconds.
- MVP makes the view passive: it forwards events and executes commands like setSaveEnabled, while a Presenter holds all presentation logic behind a view protocol.
- You test the presenter with a fake view, no UIKit.
- The difference from MVVM: MVP pushes commands, MVVM exposes state the view binds to.
- I'd pick it for UIKit without a binding layer; the cost is a view protocol that grows with every label.
What is Passive View, and how does it differ from Supervising Controller?
- In Passive View the view has zero logic.
- It forwards input, and the presenter updates the model and sets every widget, like
view.setTitle(_:). - Supervising Controller lets the view do simple declarative bindings itself, which leaves that code untested.
- Passive View is more explicit and easier to debug because nothing happens through observers.
- The cost is a chattier presenter and a fake view in every test.
You need to unit-test form validation and error display without instantiating UIKit. How do you structure the screen?
- Use a Humble View.
- Put validation and display decisions in a presenter and hide the view behind a protocol, like
protocol SignUpView: AnyObject { func showError(_ message: String) }. - In tests a fake view records what the presenter set, so you test the logic with no UIKit.
- The rule is that anything hard to test gets minimal behavior.
- The cost is a protocol and a fake per screen.
Two screens show the same model and must both update when it changes. Observer synchronization or explicit flow synchronization?
- Use observer synchronization when several screens show the same model.
- Each one just reacts to the model and ignores the others, so adding a third screen costs nothing.
- The catch is that implicit observer chains are hard to trace and debug.
- Flow synchronization updates controls explicitly and reads top to bottom, but the code has to know every dependent widget, which breaks down as screens multiply.