in the Secondary
struct, the @Binding
property is secondTime
and I want it to initially have the value from the "parent".
But when I change the value in this struct, the time
property in the parent also changes. Is there a way to get the value from the parent but prevent any changes to the value from going back up to the parent?
struct ContentView: View {
@State var time: String = "";
var body: some View {
VStack {
Text("it is: \(time)")
Secondary(secondTime: $time)
Button("Change time") {
time = "2 poclock"
}
}
}
}
struct Secondary: View {
@Binding var secondTime: String;
var body: some View {
Text("secondary time is \(secondTime)")
Button("Change time again from Secondary View") {
secondTime = "3 oclock"
}
}
}
