I am utilising SwfitUI's new @AppStorage
property. However, the willSet
property observer is not firing.
Here is my UserDefaults
value codeResult
changing from an asynchronous call:
class Main: ObservableObject {
func code(data: [AnyHashable:Any?]){
UserDefaults.standard.set("incorrect", forKey: "codeResult")
}
}
And below in my View, willSet is not being called:
struct MainView: View {
@ObservedObject var main = Main()
@ObservedObject var mainCountdown: CountDown
@ObservedObject var locationManager = LocationManager()
@State private var keyboardHeight: CGFloat = 0
@State var showCode: Bool = false
@AppStorage("codeResult") var codeResult = UserDefaults.standard.string(forKey: "codeResult") ?? "" {
willSet {
print("willSet: \(newValue)") // doesn't fire
}
didSet {
print("didSet: \(oldValue)") // doesn't fire
}
}
Any idea why it's not firing?