0

I am learning iOS development and I have stumbled across an issue where UserDefaults doesn't seem to be consistently saving correctly.

When I open the app, it checks to see if a UserDefaults property exists, if so, it does something. Now, if I save the UserDefaults property and 'synchronize', then press stop on the simulator and then press 'play' again to re-open it, sometimes the UserDefaults value is nil.

I have yet to test this on a physical device, but has anyone had the same issue - if so, is it expected?

4

1 回答 1

1

也许 UserDefaults 工作正常,但是当您将一些数据保存到 UserDefaults 并重建或运行使用Command + R(如果已经在运行模拟器)时,有时什么都没有改变(保存的数据消失)

所以每次当这种情况(必须将一些数据保存到UserDefaultsCoreData或者Realm)我首先停止并退出模拟器并重建或运行 Xcode

它对我来说很好

于 2017-01-27T11:14:28.440 回答