Search code examples
iosnsuserdefaults

Will NSUserDefaults remain if user quits app and are they global?


I'm using NSUserDefaults in my iOS app to record some specific info about the user's receipt state.

I'd like to confirm:

  • If the user quits the app, will those defaults remain?
  • Are they global, for example I'm currently using the following line to either get or set them and across different methods. I just want to be certain the data within it persists - so if I set in method1 then later method2 I use the same line to get, it will have whatever I set in method1: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

Solution

  • If the user quits the app, will those defaults remain?

    Yes, they are persistent.

    Are they global?

    Global in the sense of your whole app: Yes.

    Global in the sense of across apps: No. They are in the app's sandbox.