Passando uma Binding para Baixo
Envie o estado para uma subvisualização com o cifrão.
Passando uma Binding para Baixo é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. 🌉
Perguntas Frequentes
A aula “Passando uma Binding para Baixo” é grátis?
Sim — o texto completo de “Passando uma Binding para Baixo” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.
O que vou aprender em “Passando uma Binding para Baixo”?
Envie o estado para uma subvisualização com o cifrão. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar SwiftUI Academy?
Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Passando uma Binding para Baixo”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de SwiftUI Academy?
Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Por que as Filhas Precisam de @Binding
- Passando uma Binding para Baixo
- Criando uma Linha de Alternância Reutilizável
- @State versus @Binding