1 of 20 · UI patterns
MVC
MVC (Model–View–Controller) is an architectural pattern that separates an application's data, presentation, and coordination logic. It is the traditional architectural pattern in UIKit-based iOS development.
How it's wired
- Views send actions to the controller (target-action, delegate).
- The model notifies the controller when it changes, and the controller updates the views. Views and models never talk directly.
| Part | Owns | Looks like |
|---|---|---|
| Model | Data, state, domain logic | Structs, plus stores or services that load and save them |
| View | Display information and capture interactions | UIView, UILabel, UIButton |
| Controller | Handle events, coordinate model and view | UIViewController |
A thin controller is fine
Nothing to extract: data comes in and is rendered.
AboutViewController
An AboutViewModel, a protocol and mocks would add indirection, not value.
final class AboutViewController: UIViewController {
@IBOutlet private var versionLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
title = "About"
versionLabel.text =
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
}
}MVC is reasonable when the controller is genuinely thin.
Why MVC becomes problematic at scale
- MVC is the starting pattern. Every other UI pattern here is a refinement of it: MVVM pulls presentation out of the controller, a router pulls out navigation, and VIPER splits business orchestration from presentation.
- Massive View Controller symptoms: 1,500-line controllers, logic tied to viewDidLoad and viewWillAppear timing, code untestable without UIKit, and constant merge conflicts.
- UIKit already gives the controller a full job: lifecycle, its view hierarchy, layout, user input, and presenting other screens.
- As a feature grows, more piles on: networking, persistence, business rules, formatting, loading and error states, navigation decisions, analytics.
- This leads to tightly coupled dependencies, slow code reviews, difficult unit testing, poor reusability and expensive migrations.
- It also makes AI edits less correct and more expensive. To change one thing, an agent has to read the whole class, and a change to one concern easily breaks another. The more complex the feature, the worse it gets.
- However, Massive View Controller is not an inherent requirement of MVC. It's a consequence of poor responsibility boundaries.
- Good dependency boundaries (protocol-oriented dependencies, facades, dependency injection, feature modularization) keep an MVC codebase healthier, but they don't stop responsibilities piling into the controller. That's what MVVM and routers are for.
My decision rule
| Thin static screens (About, Licenses, simple Settings) | MVC: no presentation logic worth extracting. |
|---|---|
| Interactive screens with async state or validation (feeds, forms, search, detail views) | MVVM with a Router: keeps state and formatting testable without UIKit. |
| Complex flows where business rules and UI evolve independently (checkout, pricing, contact picker) | MVVM + Interactor, or VIPER for that flow. |
| Multi-team hierarchical business trees (ride-hailing states, logged-out vs logged-in graphs) | Consider RIBs. |
Step by step
Moving a team off plain MVC
- Find the painUse regression history, testing friction, dependency graphs and upcoming product work.
- Set principlesState ownership, dependency direction, lifecycle and module responsibilities, before choosing a pattern.
- PilotOne representative feature: complex enough to prove the approach, contained enough to limit risk.
- Migrate graduallyMVC and the new structure coexist. Extract services, inject dependencies, move presentation logic where it pays.
- Pave the roadReference implementations, templates, test utilities and clear guidelines, so nobody has to be an architecture expert.
- MeasureRegression rate, testability, onboarding friction, implementation effort and build time.
Compared
What each technique addresses
| Architectural problem it addresses | |
|---|---|
| MVC | Coupling between data and UI |
| MVVM | Massive ViewControllers |
| MVVM + Router | Coupling between feature logic and navigation |
| VIPER | Massive ViewModels and mixed presentation/business logic |
| Protocol-oriented programming | Coupling to concrete implementations |
| Dependency injection | Coupling to dependency construction |
| Feature modularization | Coupling across feature boundaries |
| Facades | Leakage of subsystem complexity |
Where MVC is enough
| Why | |
|---|---|
| Static About or legal screen | No meaningful presentation state |
| Simple image preview | Mostly rendering and gestures |
| Debug or internal tool | Low complexity and maintenance expectations |
| Throwaway proof of concept | Optimizing for learning, not longevity |
| Wrapper around a system component | UIKit already does most of the work |
| Static informational sheet | Data is passed in and rendered directly |
When to move a team off plain MVC
| Architectural response | |
|---|---|
| Business logic depends on UIKit or the view lifecycle | Extract headless services and domain logic |
| Presentation logic has complex state transitions | Introduce MVVM or a dedicated state machine |
| Testing business behavior requires loading view controllers | Separate the logic and inject dependencies |
| Navigation is tightly coupled across screens | Introduce coordinators or routers |
| Several engineers or teams keep modifying the same components | Establish feature and module boundaries |
| Features have independent lifecycles or dependency scopes | Introduce feature-scoped architecture |
| Changes keep causing unintended regressions | Explicit state ownership, contracts and testable boundaries |
| The roadmap brings substantial complexity | Add the right boundaries before coupling accumulates |
Untangling a massive view controller
| Why this order | |
|---|---|
| First: cover critical user journeys with tests | Map async work, lifecycle dependencies and shared mutable state before moving anything |
| 1. Pure computation, validation and transformation | Low risk. Easy to characterize and unit test without UIKit |
| 2. Networking, persistence and other side effects | Establishes dependency boundaries and makes tests deterministic |
| 3. Independent UI components | Cohesive views with clear inputs and callbacks; screen behavior stays the same |
| 4. Presentation logic and state transitions | With dependencies isolated, a testable ViewModel or presenter where warranted |
| 5. Navigation and feature orchestration | A coordinator, if navigation complexity or reuse justifies it |
| The order is a default | Main-thread stalls from the database: isolate persistence first. Five engineers in one file: split by feature first. Inconsistent UI from async callbacks: fix state ownership first. Stable, rarely touched: extract as features land |
Expert notes
- UI architecture is not just about organizing UI code. It's about controlling state, responsibility, coupling and the cost of change.
- In UIKit this matters because UIViewController already owns lifecycle, view hierarchy, layout and interaction handling. Adding presentation logic, business orchestration and navigation makes it an architectural bottleneck.
- These techniques solve different dimensions of complexity. You can't compensate for poor UI architecture with protocols and dependency injection: a 3,000-line view controller with perfectly injected dependencies is still a poorly structured view controller.
- Why: injection makes its dependencies swappable, but the class still does every job. It still changes for every reason, and its logic still only runs inside UIKit.
- Use MVVM from day one, even on your own, for messaging, social feeds, sign-in and onboarding, search, checkout, offline support, or any screen fed by several async sources. Their state is complex and keeps changing.
- A few simple screens can stay MVC inside an MVVM app, as long as they get their dependencies and navigate the same way as every other screen. Just don't make MVC the default for a large UIKit app.
- Team size is a multiplier, not the deciding factor. Two people building encrypted messaging may need stronger boundaries than twenty people maintaining simple CRUD screens.
- Don't add a ViewModel that only forwards calls between a view controller and a service. That's indirection without a real separation of responsibilities.
- Standardize boundaries more than patterns. One app can have MVC screens, MVVM features and state machines for complex flows. What must stay consistent is where business logic lives, who owns state, how dependencies are resolved and how behavior is tested.
- MVVM is cheap to adopt: no binding framework, just a class the view reads from. MVC costs even less, which is why it only wins on screens with no logic to move.
Check yourself
Answer out loud before you reveal. Recall is what makes it stick.
Explain MVC in 30 seconds.
- In UIKit MVC the controller mediates between model and view, and
UIViewControlleralso owns the lifecycle, so responsibilities pile up there. - MVC costs almost nothing to write, which is why I use it only where there's no logic to move: About, legal or debug screens.
- For a substantial app I default to MVVM with a Router, because the risk is business logic with no home outside the controller.
- A screen that stays thin is what would keep me on MVC.
What is "Massive View Controller" actually a symptom of?
- A missing model layer.
- In MVC the model is meant to hold the business logic and data access, not just plain structs.
- When it holds only structs, networking, caching, validation and state all land in the view controller, the only class left. The size is just the symptom.
- The fix is giving the model real objects, like a
NotesStorethat owns loading, saving and the current state. - The view controller goes back to being glue, and the logic becomes testable without UIKit.
Two tabs show the same notes. You edit in one and the other shows stale data. What's wrong with the design?
- Each screen holds its own copy of the notes, so there's no single source of truth and every edit has to be pushed by hand.
- I'd first check who writes the notes today, because two copies also mean two writes that can diverge.
- Then I'd make one store object own the notes and have both screens observe it through
@Observable, a delegate or a notification. - View controllers render state they don't own and never push data into each other.
- I'd fix ownership before touching file size.
You inherit a 1,500-line view controller. What do you extract first, and why in that order?
- I wouldn't start by converting it to MVVM.
- First I cover the critical user journeys with tests and map async work, lifecycle dependencies and shared state.
- Then I extract by risk: pure validation and transformation logic, networking and persistence behind boundaries, self-contained subviews, presentation state into a ViewModel, and navigation last, only if it's complex.
- That order is a default: if database work stalls the main thread, isolate persistence first. 1,500 lines is a signal to investigate, not proof you need a new architecture.
When would you move a team off plain MVC, and how?
- When keeping it consistent costs more than adding structure, and before view controllers get massive.
- The signals: business logic tied to UIKit or the lifecycle, complex state transitions, tests that must load view controllers, navigation coupled across screens, and repeated regressions.
- Team size multiplies these; it doesn't decide.
- Then I name the real pain points, set principles like state ownership and dependency direction before picking a pattern, pilot one representative feature, and migrate incrementally while MVC coexists, with templates and test utilities as a paved road. I standardize boundaries more than patterns.
Read it in the app's source
Done with MVC? Mark it complete. Nailing its cards builds this pumpkin, row by row.