Difference between Keychain and NSUserDefault?

Addition: When we saved userName and Password. and Remove app from device.

In Keychain: UserName and Password still is there.

In NSUserDefaults: UserName and Password also remove from device with your app.


A keychain is an encrypted container that holds passwords for multiple applications and secure services. Apple Inc. uses keychains as password management system in Mac OS and iOS.

NSUserDefaults Provides a way for application behavior customization based on user preferences. Belongs to the Foundation framework for Cocoa and Cocoa Touch.

I got this from Tag Information of NSUserdefaults and keychain


Try to avoid saving data locally as much as possible.

Keychain- Keychain is safe & encrypted way to save small storage data like username, password etc. Beware keychain data can accessible from jailbroken devices . You can get Apple sample code from here.

Keychain Sharing- Enabling keychain sharing allows your app to share passwords in the keychain with other apps developed by your team. Suppose we created two apps where users can log into the same account. It would be nice to have ability to share the login information between these apps. This way the user will only need to log in once in one of the apps.

UserDefaults An interface to the user's defaults database, where you store key-value pairs persistently across invocations of your app on a given device. UserDefaults are not secure way to save private data. UserDefaults are stored as plist locally, Anyone can track in ./Library/Preferences/com.mycompany.MyAppName.plist