V podstate, som hniezdiacich @Binding
3 vrstvy hlboké.
struct LayerOne: View {
@State private var doubleValue = 0.0
var body: some View {
LayerTwo(doubleValue: $doubleValue)
}
}
struct LayerTwo: View {
@Binding var doubleValue: Double {
didSet {
print(doubleValue)
}
}
var body: some View {
LayerThree(doubleValue: $doubleValue)
}
}
struct LayerThree: View {
@Binding var doubleValue: Double {
didSet {
print(doubleValue) // Only this print gets run when doubleValue is updated from this struct
}
}
var body: Some view {
// Button here changes doubleValue
}
}
Podľa toho, čo struct som zmeniť doubleValue
je jedno kde didSet
dostanete spustiť, takže napríklad ak by som ho zmeniť v LayerThree
len to, že jeden z nich bude tlačiť, žiadne iné bude.
Som schopný sledovať zmeny s .onChange(of: doubleValue)
čo bude potom dostať spustenie, keď sa to zmení, ale to nie je vyznať sa v mi prečo didSet
nebudú spustiť okrem na struct, kde je to zmenilo, od.
Je @Binding
struct konkrétne?