views:

89

answers:

3

After reading this thread: http://stackoverflow.com/questions/2792932/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.

+7  A: 

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.

Zydeco
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
+2  A: 

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

Shaggy Frog
+2  A: 

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