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
292
votes
15 answers

Clearing NSUserDefaults

I'm using +[NSUserDefaults standardUserDefaults] to store application settings. This consists of roughly a dozen string values. Is it possible to delete these values permanently instead of just setting them to a default value?
TonyNeallon
  • 6,607
  • 12
  • 42
  • 49
282
votes
15 answers

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

I have a login-screen in my iOS app. The username and password will be saved in the NSUserDefaults and be loaded into the login-screen again when you enter the app again (of course, NSUserDefaults are permanent). Now, the user have the possibility…
PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
275
votes
7 answers

How to store custom objects in NSUserDefaults

Alright, so I've been doing some poking around, and I realize my problem, but I don't know how to fix it. I have made a custom class to hold some data. I make objects for this class, and I need to them to last between sessions. Before I was…
Ethan Mick
  • 9,517
  • 14
  • 58
  • 74
241
votes
16 answers

Save string to the NSUserDefaults?

How to save a string into the NSUserDefaults?
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100
240
votes
24 answers

Easy way to see saved NSUserDefaults?

Is there a way to see what's been saved to NSUserDefaults directly? I'd like to see if my data saved correctly.
Ethan
  • 5,660
  • 9
  • 44
  • 51
220
votes
11 answers

NSUserDefaults - How to tell if a key exists

I'm working on a small iPhone app, and I am using NSUserDefaults as my data persistence. It only has to keep track of a few things, such as some names and some numbers so I figure I might as well keep it simple. I found this page for some…
Ethan Mick
  • 9,517
  • 14
  • 58
  • 74
217
votes
12 answers

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

I thought I knew what was causing this error, but I can't seem to figure out what I did wrong. Here is the full error message I am getting: Attempt to set a non-property-list object ( "" ) as an NSUserDefaults value for key…
icekomo
  • 9,328
  • 7
  • 31
  • 59
189
votes
12 answers

How to save local data in a Swift app?

I'm currently working on a iOS app developed in Swift and I need to store some user-created content on the device but I can't seem to find a simple and quick way to store/receive the users content on the device. Could someone explain how to store…
Nicklas Ridewing
  • 2,410
  • 2
  • 14
  • 26
178
votes
4 answers

What's the optimum way of storing an NSDate in NSUserDefaults?

There's two ways of storing an NSDate in NSUserDefaults that I've come across. Option 1 - setObject:forKey: // Set NSDate *myDate = [NSDate date]; [[NSUserDefaults standardUserDefaults] setObject:myDate forKey:@"myDateKey"]; // Get NSDate *myDate =…
John Gallagher
  • 6,208
  • 6
  • 40
  • 75
160
votes
16 answers

How can I use UserDefaults in Swift?

How can I use UserDefaults to save/retrieve strings, booleans and other data in Swift?
Mithun Ravindran
  • 2,292
  • 2
  • 14
  • 23
145
votes
6 answers

Why NSUserDefaults failed to save NSMutableDictionary in iOS?

I'd like to save an NSMutableDictionary object in NSUserDefaults. The key type in NSMutableDictionary is NSString, the value type is NSArray, which contains a list of object which implements NSCoding. Per document, NSString and NSArray both are…
BlueDolphin
  • 9,765
  • 20
  • 59
  • 74
120
votes
3 answers

NSUserDefaults removeObjectForKey vs. setObject:nil

Are the following two lines equivalent? 1. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"example key"] 2. [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"example key"]
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
112
votes
1 answer

Android equivalent of NSUserDefaults in iOS

I'd like to save some simple data. On the iPhone, I can do it with NSUserDefaults in Objective-C. What is the similar command here in Android? I'm just saving a few variables, to be reused as long as the application is installed. I don't want to use…
christian Muller
  • 5,016
  • 6
  • 34
  • 44
111
votes
6 answers

Do NSUserDefaults persist through an Update to an app in the Appstore?

Is this the case? Do NSUserDefaults get reset when you submit an update to an app on the App Store, or are they reset? My app is crashing when updated but not crashing when downloaded fully - so I'm trying to determine what could possibly be…
Nick Cartwright
  • 8,334
  • 15
  • 45
  • 56
98
votes
10 answers

Check if UserDefault exists - Swift

I'm trying to check if the a user default exists, seen below: func userAlreadyExist() -> Bool { var userDefaults : NSUserDefaults = NSUserDefaults.standardUserDefaults() if userDefaults.objectForKey(kUSERID) { return true } …
Fudgey
  • 3,793
  • 7
  • 32
  • 53
1
2 3
99 100