0Pricing
SwiftUI Academy · Lesson

@State vs @Binding

Choose the right ownership for each property.

@State vs @Binding is a free SwiftUI Academy lesson on CoddyKit. This is lesson 4 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, and your progress syncs across the web and the CoddyKit app. The SwiftUI Academy course includes 4 lessons in total.

Two Wrappers, One Goal

Both @State and @Binding manage mutable data, but they play different roles. Picking the right one keeps ownership clear. 🎯

@State Owns

Use @State when this view is the source of truth. It creates and stores the value for itself.

@State private var count = 0

@Binding Borrows

Use @Binding when the value lives somewhere else and this view only needs to read and write it.

@Binding var count: Int

Who Creates the Value

@State initializes a value. @Binding never does; it always receives one from a parent that owns it.

Mark State Private

@State is view-local, so mark it private. No one outside should reach in and set it directly.

@State private var isOn = false

Bindings Stay Open

A @Binding is not private; the parent must be able to pass a value in when it creates the child.

The Dollar Sign Link

An owners @State turns into a child @Binding through the dollar sign. That is the bridge between the two.

ChildView(count: $count)

Top of the Tree

The view highest up that truly owns the data uses @State. Everything below it borrows with @Binding.

A Simple Rule

Ask: do I create this value? If yes, @State. If a parent hands it to me, @Binding. That choice rarely fails you.

Wrong Choice, Real Bugs

Use @State where you meant @Binding and the child edits a copy. The parent never sees the change, and the UI quietly desyncs.

Same Value, Two Roles

One piece of data is @State in its owner and @Binding in every borrower. Same value, different responsibilities. 🔄

Quick Check

Quick check on choosing wrappers.

Recap: Own or Borrow

Use @State to own a value and @Binding to borrow one. Match the wrapper to who creates the data and your views stay in sync. 🧠

Frequently Asked Questions

Is the “@State vs @Binding” lesson free?

Yes — the full text of “@State vs @Binding” is free to read here on the web. 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. The SwiftUI Academy course includes 4 lessons in total.

What will I learn in “@State vs @Binding”?

Choose the right ownership for each property. 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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “@State vs @Binding” 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. Why Children Need @Binding
  2. Passing a Binding Down
  3. Building a Reusable Toggle Row
  4. @State vs @Binding
← Back to SwiftUI Academy