SwiftPumpkin

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

RequestResponseViewModelViewSends RequestInteractorBusiness logicPresenterFormats output
calls or tellsreports backData travels one way round the cycle, as plain structs. A Router handles navigation separately.
  • 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.
PartOwnsLooks like
ViewBuild Request from input, display ViewModelUIViewController
InteractorRun business logic, emit ResponseClass + worker objects
PresenterTurn Response into display-ready ViewModelClass
ModelsOne struct per hopRequest, 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 boundariesVIP, when a one-way flow is easier for them to reason about.
Everyone elseMVVM, 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.

VIPERVIP
Data flowTwo-way through protocolsOne-way cycle
Between layersProtocol calls + entitiesRequest / Response / ViewModel structs
TestingMock each neighborAssert output struct for input struct
BoilerplateHighHigh

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.

30-second answer

Explain Clean Swift (VIP) in 30 seconds.

System designAsked directly

Trace one user action through the VIP cycle. What types cross each boundary?

iOS codingAsked indirectly

A selected order must reach the detail scene without the detail screen reaching back into the list. How?

iOS codingAsked indirectly

Your presenter calls back into the view controller. How do you avoid a retain cycle and keep formatting testable?

Read it in the app's source