How to See Saved Nsuserdefaults

Easy way to see saved NSUserDefaults?

You can find the pList file for your app in the simulator if you go to:

/users/your user name/Library/Application Support/iPhone Simulator//Applications

This directory has a bunch of GUID named directories. If you are working on a few apps there will be a few of them. So you need to find your app binary:

find . -name foo.app
./1BAB4C83-8E7E-4671-AC36-6043F8A9BFA7/foo.app

Then go to the Library/Preferences directory in the GUID directory. So:

cd 1BAB4C83-8E7E-4671-AC35-6043F8A9BFA7/Library/Preferences

You should find a file that looks like:

.foo.pList

Open this up in the pList editor and browse persisted values to your heart's content.

Where is NSUserDefaults saved during development?

There is no difference between "development" and "deployment". NSUserDefaults doesn't know whether you did a debug or release build. The location should be ~/Library/Preferences/yourAppIdentifier.plist no matter what.

If you are seeing a difference between development and deployment builds, maybe check the bundle identifier (CFBundleIdentifier) in your app's Info.plist.

Also: if your app is sandboxed, your prefs will end up in the sandbox: ~/Library/Containers/yourAppIdentifier/Data/Library/Preferences/yourAppIdentifier.plist. The documentation claims that the system automatically moves your old preferences file into the sandbox, if necessary, on the first launch of the sandboxed version of the app.

NSuserdefaults Location

You can do this

Search for documents directory path

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSLog(@"documentsDirectory=%@",documentsDirectory);

That will come as

   /Users/user/Library/Developer/CoreSimulator/Devices/270568AE-FB4B-4C57-8819-4D99324D0689/data/Containers/Data/Application/C614A497-971F-4686-9162-3A614AB2C702/Documents 

now go upto

 /Users/user/Library/Developer/CoreSimulator/Devices/270568AE-FB4B-4C57-8819-4D99324D0689/data/Containers/Data/Application/C614A497-971F-4686-9162-3A614AB2C702

Then

/Library/Preferences/....plist

.plist file stores NSUserdefaults content under Root .

How to retrieve all the values Stored in NSUserDefaults?

When you save values, what you need to do is:

            var ary_Values = NSMutableArray()

if UserDefaults.standard.value(forKey: "money") != nil
{
let arr = UserDefaults.standard.value(forKey: "money") as! NSArray

for oldObj in arr
{
ary_Values.add(oldObj)
}

ary_Values.add(self.showLabel.text)
}

UserDefaults.standard.set(ary_Values, forKey: "money")
UserDefaults.standard.synchronize()

NSUserDefaults Displaying Stored Data

To save then retrieve the data, you want to do something like this:

 let textToSave = userNameTextField.text;
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(textToSave, forKey: "myKey")

Then to retrieve it and set a labels text as that (for example) do this:

let defaults = NSUserDefaults.standardUserDefaults()
myLabel.text = defaults.stringForKey("myKey")

the stringForKey method returns whatever you saved in that key previously

NSUserDefaults - storing and retrieving data

Put this text in

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
NSString *aValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"myTextFieldKey"];
NSLog(@"Value from standardUserDefaults: %@", aValue);

NSLog(@"Label: %@", myLabel);
myLabel.text = aValue;
}

And in your "edit" view in - viewWillDisappear: save changes in NSUserDefaults

iPhone - Where is the [NSUserDefaults standardUserDefaults] file stored on the computer?

It's in your app directory under:

Library -> Preferences -> bundleID.plist

You can access the data on your device.
Go into the organizer select your device then the app and there should be a download button there. If you click that it will download all the app data.

Where is a Mac Application's NSUserDefaults Data Stored?

They can be found in more than one place:

~/Library/Preferences/com.example.myapp.plist
~/Library/SyncedPreferences/com.example.myapp.plist

and if sandboxed

~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
~/Library/Containers/com.example.myapp/Data/Library/SyncedPreferences/com.example.myapp.plist


Related Topics



Leave a reply



Submit