sunshinejr / SwiftyUserDefaults

Modern Swift API for NSUserDefaults
http://radex.io/swift/nsuserdefaults/static
MIT License
4.85k stars 366 forks source link

version 4 bug - values not saved right away #172

Closed mortenholmgaard closed 5 years ago

mortenholmgaard commented 5 years ago

There seems to be some problem with values not getting saved or not saved right away. I have testede different tings and the results varies from run to run.

I have a intro flow with 3 screens each setting a Defaults value when completed and then on next open starting at the step they left of, if not completed all of them.

When I got through the flow and then reruns/installs the app from xcode it is different amost each time how many steps that has been completed - which states that has been saved. But it seems like when it gets its time they will be saved. But it is just strange..

mman commented 5 years ago

This is not a bug in SwiftyUserDefaults but rather a default behavior of underlying UserDefaults which do save settings only at certain times in the lifecycle of the app. Typically reruning the app from Xcode will kill it without giving it any chance to persist the settings to the permanent storage.

If you want to make sure settings are stored immediately there is a method UserDefaults.standard.synchronize() IIRC.

Not sure if SwiftyUserDefaults provides interface for this.

mortenholmgaard commented 5 years ago

Okay makes sense - thanks.