Closed JonnyBeeGod closed 2 years ago
Nevermind, this is actually a timing issue. Even though UserDefaults has synchronous APIs to update values it takes a couple of seconds (yea ...) for the changes to write through to disc. So this behavior is not reproducible if you wait for ~10 seconds after changing the value and then reopening the app.
Thanks @JonnyBeeGod ! 🙌🏼
Guidelines
Project Version
2.0.0
Platform and OS Version
iOS 15, iOS 13.5
Affected Devices
Tested on various Simulators
Existing Issues
No response
What happened?
When using the example project and updating one of the values like e.g.
flagEnabled
, after rebuilding the app the flagEnabled value is reset to the old value that has been saved previously before the last change.Steps to reproduce
Expected behavior
Since those values are backed by UserDefaults, I would expect them to be preserved between app launches. So that when we update a key with a new value, when starting the app again we should see the previously updated value instead of the one from before.
Attachments
No response
Screenshots or Videos
https://user-images.githubusercontent.com/2844335/147389621-c265755a-1367-409a-966e-8ce629d4cf52.mp4
Additional Information
Issue can be seen quite good in the video. This also happens if we safely move the app in the background first and then rebuild the project. Also when stepping in the code via debugger it shows that the issue is not caused by the example UI code, but the flag value returned by
AppSettings.shared.flagEnabled
is in fact the outdated value.