iphonensuserdefaults

NSUserDefaults wiped out after several sessions, Possible?


I'm storing certain values in NSUserDefaults, but after several sessions, I find nil values for those variables whenever I'm retrieving them. It's nowhere that I'm resetting them in my whole program. How can this happen?


Solution

  • If you register default defaults and set them to nil, in principle an interrupted or mismanaged write to defaults will cause a reversion to the nil default default the next time the app loads. I have never seen that happen, however. Crashes can also corrupt the defaults.

    It is more likely that you are simply accidentally setting them to nil somewhere.