5 of 22 · UI patterns
Clean Swift (VIP)
Clean Swift (VIP) arranges a screen as a one-way cycle: View → Interactor → Presenter → View. Each hop passes a plain struct (Request, Response, ViewModel), so every stage is a pure input-to-output transformation.
How it's wired
- The View sends a Request to the Interactor (business logic), which passes a Response to the Presenter, which displays a ViewModel back on the View.
| Part | Owns | Looks like |
|---|---|---|
| View | Build Request from input, display ViewModel | UIViewController |
| Interactor | Run business logic, emit Response | Class + worker objects |
| Presenter | Turn Response into display-ready ViewModel | Class |
| Models | One struct per hop | Request, Response, ViewModel |
Trade-offs
- Struct explosion: three models per use case, per screen. Group them by use case in one file, or the ceremony buries the logic.
- Async complicates the clean cycle. Responses arrive later and possibly out of order, so the interactor must own cancellation and drop stale responses.
- Routing and passing data between scenes is the hard part. Keep a router plus a small data store of what the next scene needs, separate from presentation.
When I'd use VIP
| Teams wanting VIPER-level boundaries | VIP, when a one-way flow is easier for them to reason about. |
|---|---|
| Everyone else | MVVM, with unidirectional state where screens get complex. |
Compared
VIPER vs VIP
VIPER
ViewPresenterInteractor
View and presenter talk both ways.
VIP
ViewInteractorPresenter
One-way cycle back to the view.
| VIPER | VIP | |
|---|---|---|
| Data flow | Two-way through protocols | One-way cycle |
| Between layers | Protocol calls + entities | Request / Response / ViewModel structs |
| Testing | Mock each neighbor | Assert output struct for input struct |
| Boilerplate | High | High |
Expert notes
- The idea worth keeping is unidirectional flow. VIP applies it per screen with structs; reducer architectures apply it to state itself.
Check yourself
Answer out loud before you reveal. Recall is what makes it stick.
Explain Clean Swift (VIP) in 30 seconds.
- Clean Swift's VIP runs one direction: the View sends a Request to the Interactor, which sends a Response to the Presenter, which displays a ViewModel back on the View.
- Each hop is a plain struct, so every stage is a pure input-to-output test.
- I'd use it when a team wants VIPER's boundaries with a flow that's easier to trace; the cost is three structs per use case.
Trace one user action through the VIP cycle. What types cross each boundary?
- The view controller calls the Interactor through a
BusinessLogicprotocol, passing aRequest. - The Interactor gets data from a worker, keeps it in its
DataStore, and sends aResponseto the Presenter throughPresentationLogic. - The Presenter turns that into a
ViewModeland calls the view'sDisplayLogic. - Data only flows forward, so each layer is testable with a spy on the next.
A selected order must reach the detail scene without the detail screen reaching back into the list. How?
- Let the Router pass the data.
- It adopts a
DataPassingprotocol that exposes the scene'sDataStore. - On navigation it reads the source store and writes into the destination's, like
destination.order = source.orders?[selectedRow]. - The detail scene never reaches back to the list.
- The same code path works whether you navigate by segue or by instantiating the destination and calling
show.
Your presenter calls back into the view controller. How do you avoid a retain cycle and keep formatting testable?
- Hold the view weakly through a protocol, like
weak var viewController: DisplayLogic?. - The presenter never retains the controller, and calls become no-ops once it's gone.
- Do date and currency formatting in the presenter as it maps a
Responseto aViewModel. - Then a test passes any spy conforming to
DisplayLogicand asserts the formatted strings, with no UIKit involved.