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/
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
Outlets Cannot Be Connected to Repeating Content Ios
How to Tell Swiftui Views to Bind to Nested Observableobjects
Getting iOS System Uptime, That Doesn't Pause When Asleep
Ios9 Getting Error "An Ssl Error Has Occurred and a Secure Connection to the Server Cannot Be Made"
Getting All Cookies from Wkwebview
Why Is Wkwebview Not Opening Links With Target="_Blank"
Wkwebview Equivalent for Uiwebview's Scalespagetofit
Picking Two Different Images in the Same View Controller Using Imagepickercontroller in Swift
How to Make Drawrect Work Right Now
How Add Separator to String at Every N Characters in Swift
Swift Saving and Retrieving Custom Object from Userdefaults
In Swift, How to Declare a Variable of a Specific Type That Conforms to One or More Protocols
Run App For More Than 10 Minutes in Background
How to Build For Armv6 and Armv7 Architectures With iOS 5
How to Create Percentage of Total Width Using Autolayout
Why Nsdateformatter Is Returning Null for a 19/10/2014 in a Brazilian Time Zone