Open lisindima opened 4 years ago
You cannot use @Default
in an ObservableObject
. It's meant to be used in a View
.
I agree, it would be useful to allow this, but it's currently not possible to replicate the functionality of @Published
, since it uses internal runtime inspection. More info here: https://twitter.com/olebegemann/status/1222866304786423808
There are ways to make this partly work: https://stackoverflow.com/a/59039333/64949 But I'm inclined to wait for WWDC before doing anything more, as I'm hoping it will bring the improvements needed.
Unrelated, but you don't need default: nil
when the type is optional.
From macOS 11.3 beta 2 release notes:
AppStorage property wrappers now work as expected when contained inside an ObservableObject , causing the system to emit the objectWillChange publisher. (65562845)
So we could maybe wrap @AppStorage
or something.
Good afternoon and thanks for this amazing package. I came across a small error, I can not get the view to be updated when I reset the value to default. When I close the application and open it again, I see that the value is written and is equal to the default.