In pratica, sono la nidificazione @Binding
3 livelli di profondità.
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
}
}
Qualunque sia la struttura cambia doubleValue
è quello in cui l' didSet
sarà lanciato, così per esempio se cambio in LayerThree
solo che uno di stampa, nessuno degli altri si.
Io sono in grado di controllare le modifiche con .onChange(of: doubleValue)
quale sarà quindi eseguire quando si cambia ma non fare senso per me perché didSet
non ottenere eseguito, tranne che sulla struttura in cui è cambiato dal.
È @Binding
struct specifico?