0Pricing
SwiftUI Academy · Lesson

Avoiding Unnecessary Redraws

Scope state to minimize body re-evaluations.

Avoiding Unnecessary Redraws is a free SwiftUI Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Cost of Over-Updating

If a tiny change forces a huge view to rebuild, scrolling stutters. The fix is to keep each redraw as small as possible.

State Lives Where It Changes

Put @State in the smallest view that owns it. Then only that little view re-evaluates when the value flips, not its big parent.

struct Counter: View {
    @State private var count = 0
}

Extract Subviews

Break a large body into smaller subviews. SwiftUI can then diff and skip the pieces whose inputs did not change.

var body: some View {
    HeaderView()
    FeedView()
}

Pass Only What You Need

Hand a subview just the values it reads. The fewer dependencies a view has, the less often it must recompute.

RowView(title: item.title)

Watch Observable Reads

With @Observable models, a view updates only for the exact properties it touches. Read just the fields you display.

Avoid Wide State Objects

One giant model read everywhere makes every change ripple outward. Split it so each view depends on a narrow slice of data.

Beware Closures Capturing Self

A closure that reads many properties widens a view's dependencies. Capture only the specific value the action truly needs.

Move Heavy Work Out of body

Never do expensive computing inside body. It runs often, so cache results in state or a model and read the finished value.

Use let for Constants

Mark unchanging inputs as let. Constant properties never trigger updates, signaling clearly that they cannot cause a redraw.

struct Badge: View {
    let label: String
}

Equatable Views

For costly subviews, make them Equatable so SwiftUI can compare inputs and skip re-evaluation when they match.

ExpensiveView(data: data)
    .equatable()

Optimize What You Measure

Do not guess. Scope state, extract views, then measure to confirm you actually shrank the redraws that hurt.

Quick Check

Where should you place state to limit redraws?

Recap: Avoiding Redraws

You learned to scope state tightly, extract subviews, pass minimal data, and keep body cheap. Smaller dependencies mean fewer redraws. ⚡

Frequently asked questions

Is the “Avoiding Unnecessary Redraws” lesson free?

Yes — the full text of “Avoiding Unnecessary Redraws” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “Avoiding Unnecessary Redraws”?

Scope state to minimize body re-evaluations. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Avoiding Unnecessary Redraws” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. How SwiftUI Recomputes Views
  2. Avoiding Unnecessary Redraws
  3. Lazy Loading Heavy Content
  4. Profiling with Instruments
← Back to SwiftUI Academy