0Pricing
SwiftUI Academy · Lektion

Eine Binding weitergeben

Übergeben Sie mit dem Dollarzeichen einen State an eine untergeordnete Ansicht.

Eine Binding weitergeben ist eine kostenlose SwiftUI Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des SwiftUI Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

The Dollar Sign

To turn @State into a binding you pass it, prefix the property with a dollar sign. That hands the child a live connection.

Value vs Binding

Plain name gives the current value. The dollar-prefixed name gives the binding. Same property, two ways to use it.

var count = 0
// count   -> the value
// $count  -> the binding

Owning the State

The parent declares the source with @State. Only the owner of state can create a binding from it.

struct Parent: View {
    @State private var isOn = false
    var body: some View { Text("Placeholder") }
}

Handing It Off

Inside the parents body, pass the binding into the child by writing the property name with a dollar sign in front.

var body: some View {
    ChildView(isOn: $isOn)
}

The Child Receives It

The child stores the connection in a @Binding property. Its type matches the value, like Bool or String.

struct ChildView: View {
    @Binding var isOn: Bool
    var body: some View { Toggle("On", isOn: $isOn) }
}

Types Must Match

A binding to a Bool plugs only into a @Binding var isOn: Bool. Mismatched types stop the build until you fix them.

Editing Flows Up

When the child flips its toggle, the change travels straight back to the parents @State. The parent re-renders automatically.

Forgot the Dollar Sign?

Pass the bare value where a binding is expected and Swift complains. The dollar sign is what makes it a binding.

Bindings Go Deep

A child can pass its binding further down to its own children. The same dollar sign threads state through many layers.

Read in the Child

Inside the child, use the plain name to read the current value and the dollar name when a control needs the binding back.

Text(isOn ? "On" : "Off")
Toggle("Power", isOn: $isOn)

One Line, Two Way

That single dollar-prefixed argument wires up full two-way sync. Tiny syntax, big power behind the binding. ⚡

Quick Check

Quick check on passing bindings.

Recap: The Dollar Sign Bridge

Own state with @State, pass it down with the dollar sign, receive it as @Binding. That bridge keeps parent and child in sync. 🌉

Häufig gestellte Fragen

Ist die Lektion „Eine Binding weitergeben“ kostenlos?

Ja — der vollständige Text von „Eine Binding weitergeben“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des SwiftUI Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Eine Binding weitergeben“?

Übergeben Sie mit dem Dollarzeichen einen State an eine untergeordnete Ansicht. Du übst SwiftUI Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um SwiftUI Academy zu starten?

Keine Vorkenntnisse erforderlich. SwiftUI Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Eine Binding weitergeben“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser SwiftUI Academy-Lektion Code schreiben und ausführen?

Ja. Jede SwiftUI Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum untergeordnete Ansichten @Binding benötigen
  2. Eine Binding weitergeben
  3. Eine wiederverwendbare Toggle-Zeile erstellen
  4. @State vs. @Binding
← Zurück zu SwiftUI Academy