The problem
Every SwiftUI team eventually argues about architecture, and the argument usually goes badly because people compare patterns in the abstract. A solo developer with eight screens and a team of twenty with two hundred screens need different things, and both are right about what works for them. This guide compares the four approaches you will actually meet, with the same small feature written in each, and ends with a table that maps app and team size to a choice.
The examples use @Observable, which needs iOS 17.
The feature
A list of saved articles. It loads from a service, can be refreshed, shows an error, and lets you delete an item. Every version below depends on this service:
import Foundation
struct Article: Identifiable, Hashable, Sendable {
let id: UUID
var title: String
}
protocol ArticleService: Sendable {
func savedArticles() async throws -> [Article]
func delete(_ id: Article.ID) async throws
}
Option 1: plain SwiftUI, often called MV
Views own their local state with @State. Shared state and services live in @Observable objects passed through the environment. There is no per-screen view model.
import SwiftUI
import Observation
@MainActor
@Observable
final class Library {
private(set) var articles: [Article] = []
private let service: any ArticleService
init(service: any ArticleService) {
self.service = service
}
func reload() async throws {
articles = try await service.savedArticles()
}
func delete(_ article: Article) async throws {
try await service.delete(article.id)
articles.removeAll { $0.id == article.id }
}
}
struct SavedArticlesView: View {
@Environment(Library.self) private var library
@State private var error: String?
var body: some View {
List(library.articles) { article in
Text(article.title)
.swipeActions {
Button("Delete", role: .destructive) {
Task { await run { try await library.delete(article) } }
}
}
}
.refreshable { await run { try await library.reload() } }
.task { await run { try await library.reload() } }
.alert("Couldn't load articles", isPresented: Binding(
get: { error != nil },
set: { if !$0 { error = nil } }
)) {
Button("OK") {}
} message: {
Text(error ?? "")
}
}
private func run(_ work: () async throws -> Void) async {
do { try await work() } catch { self.error = error.localizedDescription }
}
}
The app injects it once with .environment(Library(service: LiveArticleService())).
Mohammad Azam’s Is MVVM Dead in SwiftUI? documents the shift toward this style, citing Thomas Ricouard, the author of the Ice Cubes Mastodon client, as having dropped view models in favor of logic inside small views. The reasoning is that SwiftUI views are already lightweight value types bound to state, and a view model that only forwards properties adds a type without adding separation.
Good at: little code, full use of SwiftUI features like @Environment, @Query and .task, easy onboarding.
Weak at: testing screen logic without rendering views. Logic that grows inside a view is hard to reuse and hard to test.
Ricouard’s own repository is a useful reality check. The IceCubesApp README describes its architecture as straightforward MVVM for most parts, split into local Swift packages per feature. Writers who argue against view models still keep the shape that matters: shared state in observable objects and features in modules.
Option 2: MVVM with @Observable
Each screen with meaningful logic gets an @Observable view model, owned by the view with @State. Antoine van der Lee’s MVVM in SwiftUI gives the rules that keep it from turning into ceremony: start without a view model, add one when a view has presentation logic worth testing, mark it @MainActor, never let it reference the view, and name methods after user actions.
import SwiftUI
import Observation
@MainActor
@Observable
final class SavedArticlesModel {
enum Phase: Equatable { case idle, loading, loaded, failed(String) }
private(set) var articles: [Article] = []
private(set) var phase: Phase = .idle
private let service: any ArticleService
init(service: any ArticleService) {
self.service = service
}
func appeared() async {
guard phase == .idle else { return }
await refresh()
}
func refresh() async {
phase = .loading
do {
articles = try await service.savedArticles()
phase = .loaded
} catch {
phase = .failed(error.localizedDescription)
}
}
func deleteTapped(_ article: Article) async {
do {
try await service.delete(article.id)
articles.removeAll { $0.id == article.id }
} catch {
phase = .failed(error.localizedDescription)
}
}
}
struct SavedArticlesScreen: View {
@State private var model: SavedArticlesModel
init(service: any ArticleService) {
_model = State(initialValue: SavedArticlesModel(service: service))
}
var body: some View {
List(model.articles) { article in
Text(article.title)
.swipeActions {
Button("Delete", role: .destructive) {
Task { await model.deleteTapped(article) }
}
}
}
.overlay {
if case .failed(let message) = model.phase {
ContentUnavailableView("Couldn't load", systemImage: "wifi.slash",
description: Text(message))
}
}
.refreshable { await model.refresh() }
.task { await model.appeared() }
}
}
The view model is a plain class. You can test refresh() and deleteTapped(_:) with a stub service and no UI.
One trap: State(initialValue:) creates the model once per view identity, but the expression in init runs on every parent re-render. Keep the view model’s initializer cheap and do work in .task.
Good at: testable screen logic, a familiar shape for developers coming from UIKit or Android, clear place for loading and error state.
Weak at: it duplicates SwiftUI’s own state tools when overused. It also sits awkwardly with @Query, which only works inside views. In SwiftData apps, keep queries in views and give view models the actions.
Option 3: The Composable Architecture
TCA from Point-Free is a library, not a convention. A feature is a reducer with State, an Action enum, and a body that turns actions into state changes and effects. The README frames its goals as composition, testing and ergonomics. Dependencies are declared with @Dependency and swapped in tests, and TestStore asserts every state change and every action an effect sends back.
import ComposableArchitecture
@Reducer
struct SavedArticles {
@ObservableState
struct State: Equatable {
var articles: [Article] = []
var errorMessage: String?
}
enum Action {
case appeared
case loaded(Result<[Article], any Error>)
case deleteTapped(Article.ID)
}
@Dependency(\.articleService) var service
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .appeared:
return .run { send in
do {
await send(.loaded(.success(try await service.savedArticles())))
} catch {
await send(.loaded(.failure(error)))
}
}
case .loaded(.success(let articles)):
state.articles = articles
state.errorMessage = nil
return .none
case .loaded(.failure(let error)):
state.errorMessage = error.localizedDescription
return .none
case .deleteTapped(let id):
state.articles.removeAll { $0.id == id }
return .run { _ in try await service.delete(id) }
}
}
}
}
The snippet leaves out the articleService dependency registration, which is a DependencyKey conformance with live and test values.
The Thoughtworks Technology Radar placed TCA in Assess and named its narrow scope and opinionatedness as both its strength and its weakness. That is the honest summary. You get one way to do everything, exhaustive tests, and features that compose into parents cleanly. You also take on a third-party dependency that shapes every file, a learning curve for every new hire, and upgrades on the library’s schedule.
Good at: large teams that want consistency enforced by the compiler, complex state shared across many screens, apps where test coverage is a hard requirement.
Weak at: small apps, teams who will not invest in learning it, and code that leans on SwiftUI’s environment-driven features such as @Query.
Option 4: clean architecture layers
Clean architecture is a layering rule more than a UI pattern. Alexey Naumov’s long-running Clean Architecture for SwiftUI lays out three layers: views that forward user intent, stateless interactors with business logic behind protocols, and repositories that are gateways to one data source each. Dependencies point inward, and every boundary has a protocol so tests can mock it. He also lists the cost: more layers, more protocols, more setup.
In practice you can apply the useful part to any of the options above. The ArticleService protocol in this article is already the repository boundary. Add a use-case type only when business rules are shared by several screens or need tests of their own:
struct CleanUpOldArticles: Sendable {
let service: any ArticleService
let now: @Sendable () -> Date
func callAsFunction(olderThan days: Int, created: [Article.ID: Date]) async throws -> Int {
let cutoff = now().addingTimeInterval(-Double(days) * 86_400)
let stale = created.filter { $0.value < cutoff }.map(\.key)
for id in stale { try await service.delete(id) }
return stale.count
}
}
Good at: apps with several data sources, offline and online modes, or business rules shared across platforms. Weak at: small apps, where three layers for one network call is pure overhead.
Where the writers disagree
Azam and the MV camp argue view models fight SwiftUI. Van der Lee argues for view models only when they earn their place. Point-Free argues for a single enforced pattern. Naumov argues for strict layers.
This article recommends van der Lee’s middle position as the default. Start with plain SwiftUI and environment-injected @Observable services. When a screen grows real logic, such as loading phases, validation, or a multi-step workflow, give it a view model and test that. The reason is cost: you only pay for the extra type where it buys testability. Move to TCA as a team decision, before the codebase is large, not as a rescue for a codebase that is already tangled.
Traps that hurt in any pattern
- One giant environment object. A single
AppStatewith fifty properties works until every view depends on it. Split by feature. - View models that own SwiftData models across actors. Model objects are not
Sendable. Keep them on the main actor or passPersistentIdentifier. - Business logic in
body. Anything more than formatting belongs in a method you can call from a test. - Protocols for everything. A protocol with one implementation and no test double is noise. Add the seam when you need it.
- Choosing by blog post. Pick by team size and test requirements, then write the choice down so new code follows it.
Decision table
| App and team | Recommended start | Add when needed |
|---|---|---|
| Solo or two developers, under 20 screens | Plain SwiftUI with @Observable services |
View models for the two or three complex screens |
| Small team, 20 to 80 screens | MVVM for screens with logic, plain views elsewhere | Repository protocols, feature packages |
| Large team, many features, strict testing | TCA or MVVM with enforced conventions | Feature modules with interface packages |
| Multiple data sources or shared business rules | Any of the above plus use cases | Full clean-architecture layers in the data module |
| SwiftData-heavy app | Plain SwiftUI with @Query in views |
Model actors for writes, view models for workflows |
Whatever you pick, the part that lasts is the boundary between features and services. Get that right and you can change the pattern inside a screen later without touching the rest of the app.
Sources and further reading
- MVVM in SwiftUI: Using view models without overengineering Antoine van der Lee, SwiftLee
- Is MVVM Dead in SwiftUI? Mohammad Azam, AzamSharp
- IceCubesApp Thomas Ricouard
- The Composable Architecture Point-Free
- Clean Architecture for SwiftUI Alexey Naumov
- The Composable Architecture Thoughtworks Technology Radar