struct Test {
@State private var steps = UserDefaults.standard.integer(forKey: "steps") {
didSet {
steps = UserDefaults.standard.integer(forKey: "steps")
}
}
var body: some View {
Stepper("Go up or down: \(steps)", value: $steps)
.onChange(of: steps) { newValue in
UserDefaults.standard.set(newValue, forKey: "steps")
}
}
}
Using didSet
with a binding value doesn't call didSet method. Shouldn't it be called since the value is changing? So, I'm unable to save and show the saved value after this View is pushed back and forth from Navigation view. How should I solve this issue?