Questions tagged [nsuserdefaults]

NSUserDefaults is the Objective-C API for storing and retrieving user preferences in Apple's Foundation framework for Cocoa and Cocoa Touch. It is available in OS X v10.0 and later and Available in iOS 2.0 and later which is inherited from NSObject root class

NSUserDefaults provides a cross-process hierarchical key-value store for use in Cocoa and Cocoa Touch applications. It is equivalent to and compatible with the CFPreferences C API in CoreFoundation.

This class provides a programmatic interface for interacting with the defaults system.At runtime, NSUserDefaults object is used to read the defaults that an application uses from a user’s defaults database. NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value . The questions related to this can be tagged with

Source:

Question related to this are:

  1. iOS: How to store username/password within an app?

  2. Clearing NSUserDefaults

  3. How to store custom objects in NSUserDefaults

  4. Easy way to see saved NSUserDefaults?

3775 questions
10
votes
4 answers

Why I can't save WKWebView to [NSUserDefaults standardUserDefaults]?

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; [prefs setObject:self.webView forKey:@"webView"]; The code above is made to save a WKWebView object but I'm getting a compiler error: 2014-11-08 14:58:52.561 Restoration[2431:482391]…
Vulkan
  • 1,004
  • 16
  • 44
10
votes
4 answers

NSUserDefaults Values Are Lost Periodically

I use [NSUserDefaults standardDefaults] to store a boolean to see if it is the first time that application is being launched ... If so, the app should show a registration window. It was working fine till last week, but now, sometimes when I switch…
Sepehrom
  • 1,335
  • 2
  • 16
  • 33
10
votes
5 answers

Mac sandbox created but no NSUserDefaults plist

I'm trying to track down some issues arising from sandbox creation. Under multiple circumstances it appears that an NSUserDefaults .plist file is not created in Data/Library/Preferences. I have seen this in the debugger and when launching the app…
greg
  • 1,926
  • 17
  • 26
10
votes
3 answers

Can other programs read my NSUserDefaults settings?

On the iPhone, not including jail-broken phones, can other apps read the values you've set using NSUserDefaults? I'm considering saving the customer's userid/password for our service and want to make sure it is secure.
Gerry
  • 263
  • 1
  • 4
  • 10
10
votes
2 answers

NSUserDefaults synchronize not saving on

I have a bug submitted by a tester that if he performs an action and then reboots his phone (by pressing the home and Sleep/Wake button down for a few seconds) the app is not persisting state. I have been able to reproduce this issue.…
Daniel T.
  • 32,821
  • 6
  • 50
  • 72
10
votes
2 answers

NSUserDefaults won't delete object for key

When the user logs in to my application, I download a token from my JSON server and store it in NSUserDefaults, as such: [[NSUserDefaults standardUserDefaults] setValue:token forKey:TOKEN]; When the user logs out in a subsequent page, I call this…
Rambatino
  • 4,716
  • 1
  • 33
  • 56
10
votes
1 answer

Editable table view bound to NSArrayController bound to NSUserDefaultsController

I have a simple model Foo that represents a user preference and encapsulates an NSString and an NSNumber. I want to store an array of Foo’s in user defaults so that they persist between launches of the application; and I’d like to display them in an…
9
votes
3 answers

NSUserDefaults: Is it possible to get userDefaults from another app?

There are two apps installed on iPhone (myApp and competitorApp).competitorApp is saving user settings with using NSUserDefaults. I know all keys (value forKey) which using competitorApp. Is it possible to get values in myApp from competitorApp?
Voloda2
  • 12,359
  • 18
  • 80
  • 130
9
votes
2 answers

ios programming - Data argument not used by format string

I get a Data argument not used by format string error when I run the following code: - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSString *colour = ([colourArray…
gadgetmo
  • 3,058
  • 8
  • 27
  • 41
9
votes
3 answers

Why does NSUserDefaults return a deallocated string? (update #2)

In my app I write multiple strings to the defaults database, like this: [[NSUserDefaults standardUserDefaults] setObject:@"Hi" forKey:@"GREETING"]; When I call multiple times during my app life time this, then I end up with an error in the console…
openfrog
  • 40,201
  • 65
  • 225
  • 373
9
votes
2 answers

Store custom data type in @AppStorage with optional initializer?

I'm trying to store a custom data type into AppStorage. To do so, the model conforms to RawRepresentable (followed this tutorial). It's working fine, but when I initialize the @AppStorage variable, it requires an initial UserModel value. I want to…
nicksarno
  • 3,850
  • 1
  • 13
  • 33
9
votes
3 answers

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

When running an app on the iPhone (for example when you can do it in another way testing some GPS or camera feature), where can I find and check the file created by NSUserDefaults to save the standardUserDefaults ? I'm running XCode 4.
Oliver
  • 23,072
  • 33
  • 138
  • 230
9
votes
1 answer

Swift: How to check if UserDefaults exists and if not save a chosen standard value?

I am trying to check if a UserDefaults Key exists and if not set it to a standard value of my choice, but the answers here on stack overflow didn't help me to get this working. Essentially I have a couple of UISwitches, one is on and the rest is set…
RjC
  • 827
  • 2
  • 14
  • 33
9
votes
4 answers

Saving and retrieving a bool with UserDefaults

I'm trying to save a bool value to UserDefaults from a UISwitch, and retrieve it in another view. However, I've tried following multiple tutorials and stack answers and none seem to work. This is how I'm saving it: class SettingsViewController:…
Gabe12
  • 607
  • 1
  • 7
  • 25
9
votes
2 answers

Detect changes in NSUserDefaults with suiteName

In my project i use app group to transfer data to apple watch! This look like this let sharedDefaults = NSUserDefaults(suiteName: "group.com.myappname.defaults") sharedDefaults?.setObject(MyData, forKey: "DataKey") sharedDefaults?.synchronize() In…
Dmitry
  • 2,963
  • 2
  • 21
  • 39