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
9
votes
3 answers

Speed of reading NSUserDefaults vs variables

I have an app and it calls to variables often. And these variables are stored in NSUserDefaults. I'm wondering where NSUserDefaults is storing? And if I call NSUserDefaults directly instead of using variables. Which is faster? variables or…
TomSawyer
  • 3,711
  • 6
  • 44
  • 79
9
votes
2 answers

What is un-secure about NSUserDefaults, is manual encryption safe?

If I understand correctly: NSUserDefaults is an un-secure place to store sensitive data because some settings file can be hacked and the NSUserDefault values can be changed. What exactly can be hacked and not hacked? Can the Hacker see my app's…
mdamkani
  • 305
  • 2
  • 12
9
votes
4 answers

Settings bundle values returning nil

I added a Settings bundle to my app and in Xcode it appears in the root of my project tree view. The Root.plist file looks like this:
Dai
  • 141,631
  • 28
  • 261
  • 374
9
votes
2 answers

Retrieving an int from NSUserDefaults

How do I retrieve an int from NSUserDefaults? I have the following code NSUserDefaults *def = [NSUserDefaults standardUserDefaults]; NSArray *prefs = [def arrayForKey:@"addedFavs"]; favList = [[NSMutableArray alloc] initWithArray:prefs]; If I…
some_id
  • 29,466
  • 62
  • 182
  • 304
9
votes
2 answers

How to get an update NSUserDefault on iOS 4?

I am developing an iPhone application, I encounter a problem on the iOS4 because of multi task. This application has the default settings defined in a Settings.bundle. If I run my application then I left it (so it goes in the background). I'll…
Mathieu Mahé
  • 2,647
  • 3
  • 35
  • 50
9
votes
5 answers

Check if NSUserDefaults key exists

In my application, I am saving a key using this code: func saveKey(){ var xmineSpillere = mineSpillere var defaults = NSUserDefaults.standardUserDefaults() defaults.setObject(xmineSpillere, forKey: "YourKey") } But how…
Eri-Sklii
  • 549
  • 4
  • 10
  • 21
9
votes
2 answers

How persistent is [NSUserDefaults standardUserDefaults]?

I'm using [NSUserDefaults standardUserDefaults] for storing application settings. My questions are: do those settings are removed on app deletion? are they kept after an application update (through the AppStore)? Because I'm using it to store a…
jchatard
  • 1,881
  • 2
  • 20
  • 25
9
votes
4 answers

Error when trying to save image in NSUserDefaults using Swift

When i try to save an image in NSUserDefaults, the app crashed with this error. Why? Is it possible to save an image with NSUserDefaults? If not, then how do I save the image? Image... Code... var image1:UIImage = image1 var save1: NSUserDefaults…
nachshon f
  • 3,540
  • 7
  • 35
  • 67
9
votes
2 answers

NSUserDefaults vs NSCoding

When saving small amounts of data from within my App is it better to use NSUserDefaults or NSCoding? Right now I use NSCoding (encodeWithCoder/initWithCoder, etc.) but it appears that NSUserDefaults might be simpler. My total data is about a variety…
wayneh
  • 4,393
  • 9
  • 35
  • 70
9
votes
6 answers

Store CLLocationCoordinate2D to NSUserDefaults

I am new to iphone development, and i want to store CLLocationCoordinate2D object to NSUserDefaults. I am Trying [defaults setObject:location forKey:@"userLocation"]; But it gives error 'Sending CLLocationCoordinate2D to parameter of…
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
9
votes
4 answers

Is it okay to register defaults to NSUserDefaults from multiple classes in my app?

I have read and understand the way NSUserDefaults can be used to save preferences for my app to the file system. I am also aware of the need to register defaults before using them later in the app. What I am not sure of, however, is if it is okay to…
9
votes
5 answers

NSUserDefaultsDidChangeNotification: What's the name Of the Key, that Changed?

This code will call the method "defaultsChanged", when some value in UserDefaults changed NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(defaultsChanged:) …
smudo78
  • 478
  • 1
  • 3
  • 13
8
votes
4 answers

NSUserDefaults. setValue works, Not setBool

I trying to store some settings in NSUserDefaults, but It seems that the app won't store the setBool values. This works: [[NSUserDefaults standardUserDefaults] setValue: @"hello" forKey: @"test"]; [[NSUserDefaults standardUserDefaults]…
BlackMouse
  • 4,442
  • 6
  • 38
  • 65
8
votes
3 answers

How to Read String from NSUserDefaults

I have an object at the root of plist that stores objects and keys (one of which is input from a user textfield). I have no problem writing and creating structure; it's trying to read values that causing problem. Below code I used to write the data,…
Devon
  • 127
  • 1
  • 1
  • 7
8
votes
2 answers

Can someone explain the search list feature in NSUserDefaults?

I am confused about the search list feature in NSUserDefaults. The class reference says about the standardUserDefaults class method that it sets up a standard search list consisting of five domains. The docs for that method also imply that this…
herzbube
  • 13,158
  • 9
  • 45
  • 87