SwiftPumpkin

Interview prep

Architecture questions, by priority

Open a question only after you've answered it in your head.

What every answer should cover

  1. What's the essential complexity here, and what would be accidental?
  2. What does each choice cost, and what won't you build yet?
  3. Who owns the state?
  4. What is the source of truth?
  5. Which dependencies are abstracted?
  6. How do changes propagate to the UI?
  7. What survives process termination?
  8. What happens when operations fail halfway through?
  9. How do you test and evolve this system?

How answers sound at each level

WeakNames a pattern and a slogan: "MVVM, because separation of concerns."
SeniorAsks about the team and lifespan, picks a structure, names its cost.
StaffSeparates domain, runtime, team and evolution scale; contains the essential complexity even with a small team; adds seams only where change is likely; says what it won't build yet.

P0 · Architecture, prepare first

Why does UIKit MVC struggle at scale?They want: Massive ViewControllers, lifecycle coupling, testability
  • UIViewController already owns lifecycle, the view hierarchy, layout and interaction handling.
  • MVC adds presentation logic, business orchestration and navigation to the same class, so it becomes the bottleneck everything flows through.
  • The symptoms are 2,000-line controllers, logic that depends on viewDidLoad and viewWillAppear timing, code you can't test without UIKit, merge conflicts between engineers, and navigation hard-wired through prepare(for:).
  • The fix is to pull presentation into a ViewModel, navigation into a router, and business rules into services or interactors behind protocols.
  • The cost of extracting is more types and wiring, so I start with the screens that change most.

Study: MVC

Compare MVC, MVVM and VIPER. When would you choose each?They want: Responsibility boundaries, data flow, complexity
  • In MVC the controller mediates between model and view and tends to own everything.
  • In MVVM the view binds to state a ViewModel exposes, so presentation logic is testable without UIKit.
  • VIPER adds explicit view contracts and splits business orchestration (Interactor) from presentation (Presenter), with a Router for navigation.
  • MVVM with a router is my production default; MVC is the exception, for simple static screens like Settings; VIPER is for components with several independent reasons to change, such as a contact picker.
  • The trade is boilerplate against isolation.
  • I ask about domain, lifespan and team before picking, and I don't put VIPER on a settings screen.

Study: MVC MVVM (+ Router) VIPER

How do you prevent Massive ViewModels?They want: Interactors, use cases, service abstractions
  • Keep the ViewModel to presentation: state, intents, formatting.
  • Business rules move into interactors or use cases, data access into repositories behind protocols, navigation into a router, and reusable formatting into small pure types.
  • Large screens get child ViewModels per region.
  • The warning sign isn't line count, it's multiple independent reasons to change, or a ViewModel test that needs stubs for the database, network and analytics.
  • At that point introduce an interactor, or go to VIPER for that component.
  • Each split costs a type and an indirection, so I only extract where the ViewModel has a second reason to change.

Study: MVVM (+ Router) VIPER

How do you implement navigation independently of screens?They want: Router, Coordinator, deep linking
  • Screens report intent through a closure or delegate ("user picked a contact") and never construct or push the next screen.
  • A router or coordinator owns construction and transitions.
  • Model destinations as a Route enum: a deep link parses into routes, and the coordinator builds the right stack from them.
  • In SwiftUI the router owns a NavigationStack path.
  • The two things people miss: back-swipe and interactive dismissal bypass your finish callbacks, so child coordinators leak unless you observe the navigation controller; and the router must be injectable so you can test it.
  • The cost is another object per flow and lifecycle bookkeeping; for a single list-to-detail screen I skip it.

Study: Coordinator / Routing

How would you architect a large iOS application from scratch?They want: Feature modules, layering, dependency graph
  • Separate the kinds of scale first: domain complexity, runtime scale, team structure and how the product will evolve.
  • MVVM versus VIPER only answers how presentation is organized.
  • Then size the structure to the team: one or two engineers can ship SwiftUI with @Observable models and little ceremony; a single team with many screens wants MVVM with injected dependencies and navigation outside the views; several teams need feature packages behind interfaces.
  • At that scale, a domain layer holds models and ports (protocols).
  • A data layer holds repositories, networking and persistence behind those ports.
  • Feature modules each have an interface and an implementation, using MVVM with a router inside and VIPER where complexity warrants.
  • One composition root builds the graph with scopes for app, user session and screen.
  • Enforce the rules with the module graph, not wiki pages.
  • What I'd skip on day one: physical modules before there's ownership or build pain to justify them.

Study: Feature Modules Decoupled Layers Dependency Injection

Three engineers are building a chat app. What architecture do you choose?They want: Essential vs accidental complexity, team size vs domain
  • Team size isn't the whole story: chat has real domain complexity (offline sends, ordering, persistence, delivery guarantees, live updates) no matter how small the team.
  • I'd use MVVM for presentation, keep messaging and sync logic out of the UI, and put protocols around storage, networking and any vendor SDK.
  • What I wouldn't add without a concrete reason: VIPER everywhere, dozens of packages, a use-case type per operation.
  • Start with logical boundaries and promote them to physical modules when ownership, build times or enforcement demand it.
  • A small team is a reason to cut accidental complexity, not to ignore essential complexity.
  • The cost is a few protocols and some up-front wiring, which is cheap next to a message-ordering bug in production.

Study: MVVM (+ Router) Repository Decoupled Layers

How would you migrate a legacy MVC application to MVVM?They want: Incremental migration, regression prevention
  • Incrementally, never as a big-bang rewrite.
  • Start where churn and bugs are highest.
  • Write characterization tests around current behavior first.
  • Extract a ViewModel behind the same view controller, one responsibility per PR, so behavior stays identical.
  • Introduce routers at flow boundaries.
  • Put risky flows behind feature flags and watch crash and engagement metrics.
  • Leave stable, rarely touched screens alone.
  • The goal is lower cost of change where the team actually works, not architectural uniformity.

Study: MVC MVVM (+ Router)

How do you manage shared state across multiple screens?They want: Source of truth, observation, consistency
  • One source of truth per piece of data, owned at the right scope: a store or repository for the user session, not a copy per screen.
  • Screens observe it (@Observable, Combine or notifications) and render value snapshots.
  • Writes go through one API so invariants live in one place.
  • With a database, the database is the truth and the UI observes change notifications.
  • Never pass mutable models between view controllers; that's how two tabs end up disagreeing.
  • The cost is an observation layer and discipline about writes; the alternative is screens that quietly disagree.

Study: State Management Repository

How do you decouple features from databases and networking?They want: Protocols, repositories, dependency inversion
  • Features depend on domain protocols, not on Core Data or URLSession.
  • Repositories in a data module implement those protocols and map DTOs and managed objects into plain domain structs at the boundary.
  • The composition root injects the concrete implementations.
  • The payoff: features test with in-memory fakes, and storage or identity migrations happen behind the repository without touching UI code.
  • I'd skip the protocol for a dependency that will never change, since the cost is mapping code at every boundary.

Study: Repository Decoupled Layers Protocol-Oriented Programming

P1 · Architecture, prepare next

Compare MVVM, Redux, MVI and TCA.They want: Unidirectional data flow, reducers, observable state
  • MVVM mutates state inside ViewModel methods and binds the view to it.
  • Redux keeps state in a store changed only by reducers handling actions.
  • MVI does the same per screen: intents become immutable state through a reducer.
  • TCA is the Swift take on it, adding effects as values, child-store scoping, dependency management and exhaustive testing.
  • Unidirectional designs buy traceability and replayable bugs at the cost of ceremony, and they need scoping or observation becomes a performance problem.

Study: Unidirectional (TCA / Redux) MVVM (+ Router)

How do you structure SwiftUI versus UIKit applications?They want: State ownership, lifecycle, observation
  • In SwiftUI, views are values and the question is state ownership: @State for local state, @Observable models owned once and passed down, @Environment for dependencies, and navigation as data in a path owned by a router.
  • In UIKit, the view controller lifecycle is the center, so MVVM with a router and explicit bindings keeps it thin.
  • Share the domain and data layers between both, and bridge with representables where needed.
  • I don't force a ViewModel onto every SwiftUI view; small views with local @State stay simple.
  • The cost of mixing both is two ways to bind and navigate, so I keep the bridge thin and owned by one team.

Study: Declarative UI (React lineage) State Management

How would you prevent circular dependencies between feature modules?They want: Dependency graph, interface modules, DI
  • Features depend on each other's interface modules, never implementations.
  • Only the composition root imports implementations and wires them together.
  • If A needs B and B needs A, extract the shared contract into an interface module, or invert one direction with an injected protocol or event.
  • SwiftPM rejects package cycles, so a module graph check in CI turns architecture rules into build errors.
  • The cost is an extra interface module per feature; I only split once two features genuinely depend on each other.

Study: Feature Modules

How would you design a reusable component across multiple product surfaces?They want: Composition, customization, API contracts
  • Small, stable API: a configuration value type plus callbacks for intent.
  • Prefer composition and slots over boolean flags, because ten flags means a thousand untested combinations.
  • Style through design tokens, not per-caller overrides.
  • No dependencies on feature modules.
  • Build accessibility and Dynamic Type in, give it an owner, and cover each supported configuration with snapshot tests.
  • Every configuration option is a maintenance cost, so I say no to flags until a second surface needs them.

Study: Facade & Modules Protocol-Oriented Programming

How would you test navigation and presentation logic independently?They want: Mocks, spies, injected routers
  • Inject the router as a protocol.
  • In ViewModel or Presenter tests, a spy router records the routes requested while you assert state, with no UIKit involved.
  • Test coordinators by feeding them routes and asserting the resulting stack, using a fake navigation controller or a route array.
  • Keep UI tests for a few smoke flows.
  • The cost is a protocol and a spy per router, worth it because navigation bugs are slow to find through UI tests alone.

Study: Coordinator / Routing MVVM (+ Router)

When does architectural abstraction become overengineering?They want: Cost of abstraction, actual change patterns
  • When the abstraction doesn't match how the code actually changes: a protocol with one implementation and no test seam, five layers for a two-screen app, VIPER for a static settings page.
  • Every abstraction costs indirection, onboarding time and build time.
  • My heuristic: abstract at the second real use or when a team or test boundary needs a seam, and delete abstractions that never vary.

Study: Protocol-Oriented Programming Services vs Singletons

Design patterns in practice

Delegates vs closures vs observers: when would you use each?They want: UIKit event handling
  • A delegate for a component with several related callbacks and one owner, UIKit style.
  • A closure for a single callback, such as a completion or a one-off action.
  • An observer (NotificationCenter, Combine, @Observable) when many unrelated parts react and the sender shouldn't know them.
  • The lifetime rules differ: delegates are weak, long-lived closures need [weak self], and observers need their token or cancellable kept alive.
  • The classic bug is a retain cycle from a strong delegate or a stored closure capturing self.

Study: Delegate Pub/Sub

How would you propagate state changes across screens?They want: Combine, Observation, NotificationCenter
  • Put the shared state in one observable source of truth at the right scope, such as a session store or repository.
  • Screens subscribe: @Observable in SwiftUI (tracked per property), Combine publishers or async sequences in UIKit, NotificationCenter for system and app-wide events.
  • Deliver on the main actor, publish value snapshots, and never let each screen cache its own copy.
  • In database-backed apps, observe the database's change notifications so every screen converges on the same data.
  • The cost is invisible coupling: I keep event types few and typed, and don't use broadcasts for one-to-one flows.

Study: Pub/Sub State Management

How would you hide a complex subsystem behind a stable API?They want: Contacts, privacy, networking
  • Move the subsystem into its own module and export one small, protocol-shaped API: search, resolve, request permission.
  • SQL, caches, permission prompts and privacy rules stay internal.
  • Return domain errors, not the underlying framework's.
  • Split facades by capability so none becomes a god object.
  • Because consumers only see the facade, you can migrate the implementation behind it without touching them.

Study: Facade & Modules

How would you replace a legacy dependency without changing its consumers?They want: Database and API migrations
  • Keep, or extract, the interface consumers already use, then write an adapter that implements it on top of the new dependency.
  • Swap at the composition root behind a flag, and for risky migrations run old and new side by side (dual-read or shadow compare) before cutting over.
  • The adapter maps new schemas and DTOs onto the existing domain types, so consumers never change.
  • The cost is running two implementations for a while, so set a date to delete the old one.

Study: Facade & Modules Decoupled Layers

How would you support interchangeable algorithms without branching everywhere?They want: Search, sorting, retry policies
  • Model the varying behavior as a protocol (SearchRanking, SortOrder, RetryPolicy) with concrete strategies, and inject the one to use.
  • Branching moves to one place, where things are built, instead of every call site.
  • In Swift a struct of closures or an enum with associated values is often lighter than a protocol: RetryPolicy.exponential(base:max:) versus .none, chosen per request type.
  • The cost is indirection, so I don't introduce it for a branch that appears once.

Study: Protocol-Oriented Programming Dependency Injection

How would you abstract local and remote data sources?They want: Offline-first data access
  • Expose a domain-level protocol (notes(), save(_:)) and implement it over a local store and a remote API.
  • State the source-of-truth policy: offline-first writes locally and syncs through a queue, online-first fetches and caches.
  • Map DTOs into domain types, serialize access with an actor, and define staleness and conflict rules explicitly.
  • I'd skip a repository for a single endpoint with no caching; it earns its place with a second source of truth.
  • The cost is owning conflict resolution, which is where sync gets hard.

Study: Repository

How would you construct feature modules with complex dependencies?They want: Screen construction, DI
  • Give each feature a factory that takes its dependencies, as protocols, once and builds screens: makeContactPicker(entryPoint:).
  • The composition root creates it with real services; tests create it with fakes.
  • Callers never see the dependency list, a new dependency touches one place, and every call returns a fresh instance.
  • With feature modules, the factory lives in the implementation and is exposed through the interface module.
  • The risk is a factory that grows into a service locator, so it builds screens and nothing else.

Study: Factory & Builder Feature Modules

How would you decouple navigation from ViewControllers?They want: Multi-screen workflows
  • Screens emit intent and a coordinator decides what's next, creating and pushing screens itself.
  • Parents retain child coordinators and release them on finish, including back-swipe and interactive dismissal, which you detect through the navigation controller's delegate.
  • Routes as values make deep links "build this stack" instead of a chain of pushes.
  • The cost is lifecycle bookkeeping; I wouldn't add one for a single list and detail.

Study: Coordinator / Routing

How would you add caching or logging without modifying existing implementations?They want: Networking middleware
  • Wrap the implementation in another type that conforms to the same protocol: CachingClient(wrapping: client), LoggingClient, RetryingClient.
  • Compose them at the composition root, for example Logging(Caching(Retrying(network))).
  • Order matters: logging outermost so it sees everything, and the cache outside the retry so a cache hit skips retries entirely.
  • The original type and its consumers don't change, and each decorator is testable on its own.
  • The cost is layers that are harder to debug, so I keep the chain short and log at the outer edge.

Study: Protocol-Oriented Programming Dependency Injection

What problems do singletons introduce?They want: Shared services, hidden dependencies
  • Hidden dependencies that aren't in any signature.
  • Global mutable state shared between tests, which makes them order-dependent and breaks parallel runs.
  • Process-long lifetime: logout can race a background save and leak data across accounts, and multiple accounts become impossible.
  • One instance is fine; global access is the problem.
  • Migrate with a protocol and default-argument injection, call site by call site, and scope user data to a session.

Study: Services vs Singletons

How would you represent a complex asynchronous workflow?They want: Message delivery, uploads, authentication
  • An enum of states with associated data and one transition function: idle → uploading(progress) → retrying(attempt) → sent, or failed(error).
  • Invalid transitions become impossible or explicit errors.
  • The UI renders from the current state, and side effects fire on transitions.
  • For delivery and uploads, persist the state so it survives termination, and make transitions idempotent so retries and duplicate events are safe.
  • The cost is spelling out every state up front, which is exactly the point for delivery and auth flows.
  • I reach for one when a flow has more than a few states or must survive relaunch; a simple loading flag doesn't need it.

Study: Unidirectional (TCA / Redux) Coordinator / Routing

How would you model operations that can be queued, retried or undone?They want: Offline operations, message sending
  • Make each operation a value: SendMessage(id, payload), DeleteNote(id).
  • Values can be persisted in a durable outbox, executed when online, retried with backoff, deduplicated by id and undone with an inverse command.
  • For offline sending: write to the outbox first, process in order per conversation, and attach an idempotency key so the server drops duplicate retries.

Study: Unidirectional (TCA / Redux) Repository

How would you represent nested UI components or hierarchical data?They want: View trees, threads, folders
  • Give leaves and containers one interface so code walks the tree uniformly.
  • UIKit's view hierarchy and child view controllers are composites, and every SwiftUI view composes views.
  • For hierarchical data (folders, threaded replies, settings sections) use a recursive struct or an indirect enum, rendered with recursive views or OutlineGroup.
  • Mind stable identity and lazy loading for deep trees.
  • The risk is unstable identity: give every node a stable id, so expanding or editing one node doesn't reset state or animations elsewhere in the tree.

Study: Declarative UI (React lineage)