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

How secure is NSUserDefaults on iOS 8,9?

In-App Purchase Programming Guide suggests you can persist In-App purchase in NSUserDefaults here. However I found this article saying that it is insecure and data in it are easily accessed and modified: NSUserDefaults are stored in plist in…
Rasto
  • 17,204
  • 47
  • 154
  • 245
24
votes
2 answers

NSLocale preferredLanguages objectAtIndex:0 always return "en"

Simulator's language already changed to Japanese, why [[NSLocale preferredLanguages] objectAtIndex:0] always return "en"? Neither preferred language nor region is related to "en", where does "en" come from? Tried to get [[NSLocale…
S1U
  • 825
  • 2
  • 14
  • 26
23
votes
1 answer

Understanding the UserDefaults register method

First of all, let me say that this is NOT a complaint, I just want to understand how does the register(defaults: []) method works. I'm using the UserDefaults register(defaults: []) method inside the didFinishLaunchingWithOptions method to register…
fs_tigre
  • 10,650
  • 13
  • 73
  • 146
23
votes
1 answer

How to receive NSUserDefaultsDidChangeNotification iphone

After a lot of searching I was not able to find whether you need to pass a dictionary object to: [NSUserDefaultsDidChangeNotification addObserver: forKeyPath: options: context:]; and what should be provided in options if I want to be notified for…
neha
  • 6,327
  • 12
  • 46
  • 78
23
votes
5 answers

NSUserDefaults not working on Xcode beta with Watch OS2

I just installed the latest beta of Xcode to try Swift 2 and the improvements made to the Apple Watch development section. I'm actually having an hard time figuring out WHY this basic NSUserDefaults method to share informations between iOS and Watch…
Sara Canducci
  • 6,231
  • 5
  • 19
  • 24
23
votes
3 answers

Difference between Keychain and NSUserDefault?

I am new to objective C, I have created one application in that I have used both NSUserDefault and Keychain to store my user name and password. But I cant differentiate both. Please help to differentiate the both. Thank you.
Ganapathy
  • 4,594
  • 5
  • 23
  • 41
22
votes
6 answers

How to retrieve values from settings.bundle in Objective-c/Swift?

I have created a project that set and retrieve values from settings.bundle. I have also set some defaults values in settings.bundle file. Now the problem is when I retrieve values as NSUserDefaults *defaults = [NSUserDefaults…
Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107
22
votes
6 answers

Hundreds of accesses to "InputModeProperties.plist" are lagging my game (iPhone)

I have a weird problem with a bugfix for Tiny Wings. In my game i use something like: NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setFloat:musicVolume forKey:@"musicVolume"]; for saving some preferences…
22
votes
8 answers

How can I save and then load a JSON in NSUserDefaults with SwiftyJSON?

in my iOS project I need to save an entire JSON as user data and then reload it on next app launch. Squashing it into many values and then recreate the JSON is not an option, I just need some serializable way of saving the entire raw JSON. I tried…
Michele Bontorno
  • 1,157
  • 2
  • 13
  • 27
22
votes
7 answers

(Swift) Storing and retrieving Array to NSUserDefaults

I am trying to store an array to NSUserDefaults and retrieve the array when needed to populate a UITableView. Currently I am using: //store data NSUserDefaults.standardUserDefaults().setObject(myArray, forKey: "\(identity.text!)listA") …
William Larson
  • 593
  • 3
  • 8
  • 16
22
votes
5 answers

How to auto clear NSUserDefault values in swift?

How can I auto clear the nsuserdefault values in swift? I have already tried this but it doesn't work for me... [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
B.Saravana Kumar
  • 1,208
  • 6
  • 20
  • 48
22
votes
5 answers

How to print NSUserDefaults content in Swift

How do you print all the content of NSUserDefaults? I need to see everything that has been stored into NSUserDefaults. Is there a simple way to print that or to see it into the logs? In Swift! Thank you
ernestocattaneo
  • 1,197
  • 5
  • 18
  • 30
21
votes
6 answers

NSUserDefaults errors in logs

I get some error messages in logs [User Defaults] Failed to write value for key GameId in CFPrefsPlistSource<0x1740faf00> (Domain: xxx.xxxxxx, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null)): Path not accessible, switching to…
Valentin Shamardin
  • 3,569
  • 4
  • 34
  • 51
21
votes
4 answers

Swift NSUserDefaults setString:forKey:?

NSUserDefaults has integerForKey:, setInteger:forKey: and stringForKey:, but does not have setString:forKey:. How do you set a string to NSUserDefaults? It has setObject:forKey: but, in Swift, String is a struct. Is it ok to use setObject:forKey: to…
Yoichi Tagaya
  • 4,547
  • 2
  • 27
  • 38
21
votes
1 answer

When should I use the various storage mechanisms in iOS?

I thought this would be covered already, but my search returned nothing of relevance. I am aware that there is NSUserDefaults, Core Data, object archiving, raw SQLite, plists, and of course, storage by web servers. What is unclear and somewhat hazy…
user
  • 3,388
  • 7
  • 33
  • 67