Passare un binding verso il basso
Passi lo stato a una sottovista con il simbolo del dollaro.
Passare un binding verso il basso è una lezione SwiftUI Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento SwiftUI Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso SwiftUI Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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 bindingOwning 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. 🌉
Domande Frequenti
La lezione «Passare un binding verso il basso» è gratuita?
Sì — il testo completo di «Passare un binding verso il basso» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso SwiftUI Academy, passa a CoddyKit PRO. Il corso SwiftUI Academy include 4 lezioni in totale.
Cosa imparerò in «Passare un binding verso il basso»?
Passi lo stato a una sottovista con il simbolo del dollaro. Eserciti SwiftUI Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare SwiftUI Academy?
Non è richiesta alcuna esperienza precedente. SwiftUI Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Passare un binding verso il basso»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione SwiftUI Academy?
Sì. Ogni lezione SwiftUI Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Perché i figli hanno bisogno di @Binding
- Passare un binding verso il basso
- Creare una riga Toggle riutilizzabile
- @State e @Binding a confronto