sunshinejr / SwiftyUserDefaults

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

Changes not persisted to disk immediately #133

Closed humayunharoon closed 7 years ago

humayunharoon commented 7 years ago

I noticed this during my testing, if i add or remove values and kill the app asap, on my next session my addition or removal didn't get saved to disk. I think this has to do with the synchronisation call that needs to be made to persist changes to disk.

Am i doing something wrong, or is it indeed the case? and if so, can we maybe add an optional method that immediately flushes changes to disk?

radex commented 7 years ago

The method already exists, and it's Defaults.synchronize(). Note that it's not recommended to use it in normal circumstances. But if you need to ensure synchronization for testing reasons, there you go