UserDefaults getting erased on Simulator, some Devices

UserDefaults are getting erased for me on the Simulator (15.0) every time. Some users (iOS/iPad OS 15.0.2) are reporting to me that my app is erasing all their settings after re-launch.

In the Simulator, I can reproduce this by quitting the app and relaunching it manually. The same procedure does not cause loss of date on my iPhone or iPad running 15.0.2, but does for a handful of my users.

All of the many posts related to this issue seem to be at least 5 years old, but I am having the problem now.

Replies

Are you only seeing this issue in iOS 15? It could be a regression, and you should file this on Feedback Assistant.

Thanks so much for your quick reply. I have been able to isolate the problem and it turns out to be the programmer (aka me).

  • I need to follow up again, as although I was indeed introducing a bug to try to solve the issue, it ended up not solving the bug. UserDefaults were sometimes not being read correctly and values had become corrupted. After speaking directly to an Apple engineer, it seems that there may have been an issue with file protection upon launch: the existence of the keys was seen but their values were all 0 or corrupted object data.

Add a Comment