views:

193

answers:

3

In the application I'm working on, I'm generating a username and password and storing them in [NSUserDefaults standardUserDefaults]. I know there's some system-wide information you can retrieve from there; does that mean all the applications on the phone have access to everything in there? I'm currently prefixing the keys I'm using in there with some strings of characters related to my application name to avoid conflicting with other applications, but is this necessary? And if so, is there a better way to avoid such collisions?

+2  A: 

No. NSUserDefaults are not system wide. Name them whatever you like, you'll be fine. :)

Brandon Schlenker
+8  A: 

You should also be storing usernames and passwords inside of the keychain and not in user defaults. Storing them in user defaults open them up to snooping when backing up the data to their Mac.

Mike Shields
+1  A: 

NSUserDefaults uses the abstract concept of "search paths" to look for defaults values. Unless you customize it, the standard user defaults object will look in three places; the launch arguments, your application's preferences, and the system preferences (for example global localization options). You can also manually add identifiers for other search paths, if you wanted to share the same preferences between more than one application (I haven't tried this with the iPhone, so I'm not sure if it's available on Cocoa Touch or if you can only do this on OS X).

You could potentially have a conflict with one of the systemwide preferences, but since your application's search path is searched first it's never an issue.

Marc Charbonneau