Why the compiler gives up on long view bodies
The compiler checks a whole view body as one expression, and a long one can run out of budget, often because of a small mistake somewhere inside. How to find the real error, and the changes that keep it from coming back.
Because the compiler works out the types in a whole expression at once, and a view body is one expression. A
List or ForEach row, a chain of modifiers and every number literal are choices it has to settle together. When
there are too many combinations to try, it stops and reports this error instead of an answer:
error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Often the body isn’t too big. It has a mistake in it. In our tests on Xcode 27.2, a list row that type-checked in a
fraction of a second gave this error after a one-letter typo, and the error pointed five lines away from it. The fix that
shows the real error and keeps the error away is the same: move rows and sections into their own small views. The
quick fix is to write the type of the closure’s parameter, as in { (item: Item) in.
The short version
| What you see | What’s usually going on | What to do |
|---|---|---|
| The error on a view body that compiled before your last edit | A mistake in that edit: a typo, a wrong type, a wrong argument | Look at the lines you just changed, or move the row into its own view to get the real error |
| The error on a long body you’re still writing | Too many choices in one expression | Move rows and sections into their own views |
| The error on a line of arithmetic | Number literals with no type to anchor them | Write the type: let x: Double = …, or CGFloat(…) on one value |
| No error, but one file always takes long to compile | Expressions that are slow but finish in time | Turn on the two slow type-check warnings below |
Why the compiler gives up
The Swift project’s own description of its type checker says it “limits the scope of type inference to a single
expression or statement, for purely practical reasons”
(Type Checker Design and Implementation).
Within that expression, every literal starts out with no type: “A literal expression, such as 17, 1.5, or
"Hello, world!", is assigned a fresh type variable.” 1.5 can be a Double, a CGFloat or a Float, and 2 can
be any of those or an Int. Every overloaded name, such as +, *, an initializer with several forms or a modifier
with several signatures, is a choice too, and the solver “explores both possible bindings” until it finds the one
that works. The same document is plain about the cost: “Solving the constraint systems generated by the Swift
language can, in the worst case, require exponential time.”
So the compiler gives itself a budget. The “reasonable time” in the error isn’t only a clock: the compiler also caps how many combinations it tries and how much memory the search uses, and it stops at the first limit it hits. It’s not a slow Mac, then. The same code fails the same way on every Mac.
Arithmetic shows it in one line. On Xcode 27.2, this fails:
let x = 1 + 2.5 * 3 - 4 / 2 + 1 + 2 * 3 - 4
Every number and every operator is open, and nothing says what x should be. Give the result a type, and the same
line checks at once:
let x: Double = 1 + 2.5 * 3 - 4 / 2 + 1 + 2 * 3 - 4
Real code rarely looks like that, because variables already have types and each one narrows the search. In our
tests, a layout calculation with CGFloat parameters and a few literals checked quickly. The worst case is many
literals with nothing typed around them.
Why a small mistake turns into this error
A view body is one expression built from nested closures: the NavigationStack, its VStack, the List, the row,
each modifier. When everything in it is right, the compiler usually finds the answer quickly. When something is
wrong, there’s no combination that works, so it keeps trying others. It tries every way to read every part of the
body before it can say none of them fit, and that’s where it runs out of budget.
We checked this on Xcode 27.2 with an ordinary list row: a title, a note, a price, and a highlight on the row you tap. As written here, it type-checks in a fraction of a second:
List(items) { item in
HStack(spacing: 8) {
VStack(alignment: .leading) {
Text(item.title).font(.headline)
Text(item.note ?? "No note").font(.caption).foregroundStyle(.secondary)
}
Spacer()
VStack(alignment: .trailing) {
Text(item.price, format: .currency(code: "USD")).font(.body)
Text("x\(item.count)").font(.caption)
}
}
.padding(.vertical, 4)
.background(selected == item.id ? Color.blue.opacity(0.1) : Color.clear)
.onTapGesture { selected = item.id }
}
Then we made one mistake at a time on the price line:
| The mistake | What the compiler said |
|---|---|
A typo: item.prce |
“unable to type-check”, after a long search, pointing at the title line five lines up |
A wrong type: item.price * item.count (a Double times an Int) |
The same: “unable to type-check”, at the title line, after a long search |
A wrong argument: .padding(item.count + 0.5) |
The real error, at once: “cannot convert value of type ‘Int’ to expected argument type ‘CGFloat’” |
An optional where a String is needed: Text(item.note) |
The real error, at once: “value of optional type ‘String?’ must be unwrapped” |
So it isn’t every mistake, and it isn’t the size alone: without the highlight (the .background line or the
.onTapGesture line), the typo came back as its real error. The more the row’s pieces depend on each other, the
more combinations a mistake sends the compiler through. The error’s position doesn’t tell you where the mistake is.
It marks the expression the compiler gave up on, which can start lines away from the typo. And the long search
comes back on every build until the mistake is fixed. The results were the same in Swift 6 language mode.
How to find the real error
Move the row into its own view
This is the fix that pays off twice. A view’s body is checked on its own, so a row in its own struct is a small
expression, and the List that uses it becomes a small expression too:
struct OrderRow: View {
let item: Item
let isSelected: Bool
var body: some View {
HStack(spacing: 8) {
VStack(alignment: .leading) {
Text(item.title).font(.headline)
Text(item.note ?? "No note").font(.caption).foregroundStyle(.secondary)
}
Spacer()
VStack(alignment: .trailing) {
Text(item.price, format: .currency(code: "USD")).font(.body)
Text("x\(item.count)").font(.caption)
}
}
.padding(.vertical, 4)
.background(isSelected ? Color.blue.opacity(0.1) : Color.clear)
}
}
// In the parent view:
List(items) { item in
OrderRow(item: item, isSelected: selected == item.id)
.onTapGesture { selected = item.id }
}
With the row split out, the typo gave its real error at once, on the right line: “value of type ‘Item’ has no
member ‘prce’”. Apple’s advice for complex expressions points the same way: “Rather than use such a complex
expression, it’s better to create something simpler and more readable”
(Improving build efficiency with good coding practices).
A row view is also easier to preview and reuse. A @ViewBuilder function or computed property in the same view
splits the code too.
Or write the closure parameter’s type
When you can’t restructure right now, tell the compiler what the closure receives:
List(items) { (item: Item) in
// the same row as before
}
In our test, that one change was enough for the typo to come back as “value of type ‘Item’ has no member ‘prce’”,
at the right line, at once. Without the type, the compiler has to work out what item is from the List, while
it works out which way of building the List fits the row; with it, the row starts from a known type. It’s the
smaller change, and a good way to find the mistake; a separate view is still the better shape for a long row.
Or take the body apart
If the error points at a large body and nothing looks wrong, comment out half of it (or replace a section with
EmptyView()) and build. If the error goes away, the mistake is in the half you removed; if it doesn’t, it’s in the
half you kept. A few rounds find the line. The lines you changed since the last good build are the place to start.
How to keep it from coming back
Give values their types
Apple’s guidance: “Providing explicit type information reduces the work the compiler must do, and also allows it to do more error checking.” The places it matters most are the ones the compiler has the least to go on:
- Arithmetic with literals:
let spacing: CGFloat = 8 * 2 + 4instead oflet spacing = 8 * 2 + 4, which is anIntthat then has to be converted. - Closures passed to views: the parameter types, as above, in rows you can’t split out yet.
Keep calculations out of the body
Work out sizes, labels and filtered lists in a computed property or a small function with a declared return type,
and let the body use the result. private var total: Double { … } is checked on its own; the same calculation
inside a Text’s interpolation is part of the body’s expression.
Turn on the slow type-check warnings
Expressions can also be slow without failing: they finish inside the budget, but they slow down every build of that file. Two compiler flags make them visible. Add them to the Debug configuration, and the compiler warns about any function or expression that takes longer than the limit, in milliseconds, to type-check:
Find it Build Settings › Other Swift Flags (Debug)
Key OTHER_SWIFT_FLAGS
Debug value Add the two flags below
-Xfrontend -warn-long-function-bodies=200
-Xfrontend -warn-long-expression-type-checking=200
The warning names the line and the time, for example “expression took …ms to type-check (limit: 200ms)”. Fix what it flags with the same changes as above, and lower the limit once the list is short. Our guide to the build timeline shows how to see which files take longest to compile in the first place, and why a one-line change rebuilds so much covers the other places a small edit’s build time goes.
Hand it to your coding agent
Agents hit this error often: they write long view bodies, and a small mistake inside one turns into an error that doesn’t say what’s wrong. To have one find the slow and failing expressions in your project and fix them, give it this:
Read https://quickfirebuild.com/blog/unable-to-type-check/. Then, in the project folder, check that the working tree is clean; if it isn't, stop and tell me.
Build the main scheme for a Simulator destination with the two warning flags added on the command line only, keeping the project's own flags (don't edit the project): OTHER_SWIFT_FLAGS='$(inherited) -Xfrontend -warn-long-function-bodies=200 -Xfrontend -warn-long-expression-type-checking=200'. Collect every "unable to type-check" error and every slow type-check warning, with file, line and time.
For each one, apply the article's fixes in this order: move the row or section into its own view, write closure parameter types, give literal-heavy values a type, move calculations out of the body. Keep behavior and appearance the same. Build again after each file, and confirm the error or warning is gone.
When you're done, list what you changed per file and anything you left alone, and why. Don't commit.
What’s left
The error is the compiler running out of budget on one expression, and usually a mistake is what makes it run out. Small views, typed closure parameters and typed literals give the compiler less to search and give you the real error back. Quickfire, which we’re building, is for the rest of the wait: faster everyday builds of large apps, on the project you already have. Early access opens in early 2027.