4

After reading this thread: NSUserDefaults not present on first run on simulator

I know it's quite easy to store some app data in the [NSUserDefaults standardUserDefaults]. But if other applications also happen to use the same key to store their data, is this possible that my app data gets overwritten?

Many thanks to you all.

Community
  • 1
  • 1
bobo
  • 8,439
  • 11
  • 57
  • 81

3 Answers3

12

No, each application has it's own defaults, saved in a different file based on the application's bundle ID. On the iPhone (and simulator) each app has it's own home directory too, and can't access other app's files.

Jesús A. Álvarez
  • 2,958
  • 23
  • 22
  • This answers the question correctly but provides information outside of the question's scope that is misleading. Reads are through a series of databases, although the databases are either system-wide or belong to your application, not other applications. See the documentation for standardUserDefaults for more. – Steven Fisher Jun 15 '10 at 18:42
4

No. When you store something in NSUserDefaults standardUserDefaults, it's primarily a collection for your application. Other apps on the iPhone can't store there.

However, if you read keys other than what you stored, you may get back a value from the system database. This won't be other applications' data, but something related to the iPhone itself. I think the keys are undocumented, though.

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
2

Each application has its user defaults sandboxed from each other. You won't run into any collisions.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128