where is nsuserdefaults stored ?

One question arises in every IOS programmer , That whats the easy way to save some value without using any Database.Second questions is arise can i see the data i saved .where is nsuserdefaults stored ?

Answer is “Yes” .

The easiest way to save data in IOS is using NSUserDefaults and also you ca see the data what you saved .

NSUserDefaults : An interface to the user’s defaults database, where you store key-value pairs persistently across launches of your app.

Declaration : @interface NSUserDefaults : NSObject

where is nsuserdefaults stored ?

Overview
The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user’s preferences.

Storing Default Objects
The NSUserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Boolean values, and URLs. These methods are described in Setting Default Values.

Example

Storing
Objective-C

swift

Retrieving

objective-c

swift

A default object must be a property list—that is, an instance of (or for collections, a combination of instances of) NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object, you should typically archive it to create an instance of NSData.

Is there a way to see what’s been saved to NSUserDefaults directly?

Use this to get the location of your apps directory: print(NSHomeDirectory()) from that location, go to Library>Preferences><yourAppsBundleName.plist> this will be where NSUserDefaults is saving your data.

Swift 3.x & 4.x

For retrieving the complete dictionary representation of user defaults:

print(Array(UserDefaults.standard.dictionaryRepresentation()))

For retrieving the keys:
// Using dump since the keys are an array of strings.

For retrieving the values:

We can use dump here as well, but that will return the complete inheritance hierarchy of each element in the values array. If more information about the objects is required, then use dump, else go ahead with the normal print statement.

Read Also : How to Add Multiple Buttons in UIAlertView in IOS !

Swift 2.x

For retrieving the complete dictionary representation of user defaults:

For retrieving the keys:

For retrieving the values:

Easy, since the plist file name is <app-bundle-identifier>.plist, you can use find command to find its path. But it will take very long if you search your whole computer, so you have to pick a good scope, like ~/Library/Developer/CoreSimulator

example:

For Xcode 7

NSUserDefaults standardDefaults are stored here: