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
8
votes
1 answer

Where does NSUserDefaults store data on Mac OS X?

I'm working on a Mac OS X app that was developed for Mountain Lion. The app performs some setup tasks the first time it runs. It then sets a flag in [NSUserDefaults standardUserDefaults]; on subsequent runs the app checks to see if that flag is set,…
Greg
  • 33,450
  • 15
  • 93
  • 100
8
votes
2 answers

How to convert bool to NSObject in MonoTouch

This is making me a little crazy. I'm trying to register some NSUserDefaults in my MonoTouch app. var defaultsToRegister = new NSMutableDictionary(); defaultsToRegister.SetValueForKey(true,…
David Clarke
  • 12,888
  • 9
  • 86
  • 116
7
votes
2 answers

How to access iOS UserDefaults stored data in Flutter SharedPrefrences

I have an iOS app already on Store, Now planning to replace it with Flutter with new version release. I want to get access native app's UserDefaults data in Flutter code. Using the way suggested in Flutter docs I m getting null value. What I have…
M Zubair Shamshad
  • 2,741
  • 3
  • 23
  • 45
7
votes
1 answer

How to know if window is minimizable when titlebar was double clicked?

This image is from SystemPreferences > Appearance I want to know How do I get that value programmatically? I ask because I am drawing a window with a customized titlebar and I want it to resemble (in behavior) as much as possible to normal…
nacho4d
  • 43,720
  • 45
  • 157
  • 240
7
votes
1 answer

Backing up NSUserDefaults and synching iPhone

Is the application domain in [NSUserDefaults standardUserDefaults] backed up when the user synchs their device? If not, can you suggest a close correct alternative? Apple makes reference to "Application Preferences" in its documentation, such as…
Ken
  • 30,811
  • 34
  • 116
  • 155
7
votes
3 answers

Why is NSUserDefaults leaving temporary plist files in Library/Preferences for my app?

I'm having trouble figuring out why NSUserDefaults is leaving junk plist files in Library/Preferences for my app. I'm seeing the following files... com.mycompany.myapp.plist com.mycompany.myapp.plist.3gaPYul com.mycompany.myapp.plist.c97yxEH ...…
bsneed
  • 579
  • 4
  • 8
7
votes
2 answers

Why is it obvious to not store password in NSUserDefaults?

I've been googling around on how to store a password, and most of the people say that the only acceptable option is Keychain. I implemented that kind of approach, due to rush. But now I am curious what is that obvious thing to not store passwords in…
Miras Maratuly
  • 216
  • 2
  • 14
7
votes
2 answers

Is it bad form to synchronize NSUserDefaults in -(void)dealloc?

I load from NSUserDefaults in my object's init method. Can I save to NSUserDefaults in my object's dealloc method? Something exactly like: -(void)dealloc { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults…
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78
7
votes
2 answers

Saving Array of Struct with NSKeyedArchiver and Userdefault in which object conform to NSCoding

As a Protocol oriented programming concept, I have created my model with Struct. I want to save Array of "Struct" into Userdefault. But I am having a problem in encode/decode of the array of this model. Here is my model Struct struct Room { let…
Wolverine
  • 4,264
  • 1
  • 27
  • 49
7
votes
1 answer

Attempt to set a non-property-list object - NSUserDefaults

I couldn't find reason how I have got an error when I am trying save Dictionary in the NSUserDefaults. There is a really simple class function: class func userLoggedIn(udid udid: String, username: String, email: String, userData: [String:…
Dzeremix
  • 446
  • 1
  • 5
  • 24
7
votes
2 answers

NSUserDefaults - should your app's key names be fully qualified?

I have an iOS app, and as usual I store the user's preferences in NSUserDefaults (or UserDefaults as it is now called in Swift). let ud = UserDefaults.standard let foo = 123 ud.set(foo, forKey: "foo") ud.integer(forKey: "foo") Should key names be…
Rob N
  • 15,024
  • 17
  • 92
  • 165
7
votes
1 answer

How can I reset UserDefaults for XCTestCase?

I'm trying to be good and writing unit tests for my classes, but I have some classes that deal with preferences and checking for first run. The test functions I've written work fine the first time they're run, but subsequent tests fail because the…
Kudit
  • 4,212
  • 2
  • 26
  • 32
7
votes
3 answers

How can I remove value that was previously registered via [NSUserDefaults registerDefaults:] call

I have bunch of preference values registered via [NSUserDefaults registerDefaults:] call on application startup. I need to replace them at some stage with new ones but new values scope (keys set) is less than initial one. So after I call…
macwasik
  • 71
  • 2
7
votes
6 answers

Removing a key from NSUserDefaults not working

I have a logout function in my app. Seems to be a weird problem where it doesn't save the NSUserDefaults. Here I simply want to remove the key. However after logging out if I then open the app again it will find that this key is still in the…
KexAri
  • 3,867
  • 6
  • 40
  • 80
7
votes
2 answers

Delete all my NSUserDefaults that start with a certain word

Is there a way for me to "walk" through a list of all the NSUserDefaults in my iPhone app, and only delete certain ones? For example, I'd like to get all the key names that start with a certain word. Something like this: [[NSUserDefaults…
Patricia
  • 309
  • 3
  • 11