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

Changing default value of User Default boolean Swift

I have the code: let userDefaults = NSUserDefaults.standardUserDefaults() if let branchcheck = userDefaults.boolForKey("someBooleanValue") as Bool? { println("found boolean as \(branchcheck)") } This is grand, only when…
Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
7
votes
5 answers

Save a tuple in NSUserDefaults

I'm using a tuple to store something like this. var accessLavels: (hasInventoryAccess: Bool, hasPayrolAccess: Bool) accessLavels = (hasInventoryAccess: true, hasPayrolAccess: false) Now I want to save it in…
Isuru
  • 30,617
  • 60
  • 187
  • 303
7
votes
4 answers

NSWindow with NSWindowTitleVisibilityNone saving incorrect frame to user defaults?

My app has an option that allows the user to choose between the standard "full-size" window titlebar/toolbar and the "compact" titlebar/toolbar made available in the NSWindow 10.10 API. Specifically, I'm using the -titleVisibility method to set…
Ben Stock
  • 1,986
  • 1
  • 22
  • 30
7
votes
2 answers

storing [NSNull null] values in NSUserDefaults, from JSON serialization, causes unwanted exceptions

I've got an app where I use a JSON based API. As part of JSON, often values are set to "null". This may be common: {"data":["one","two","three"],"name":null,otherstuff:10} Recently I've tried to store a misc NSDictionary hierarchy, converted from…
Miro
  • 5,307
  • 2
  • 39
  • 64
7
votes
5 answers

Xcode 6 NSUserDefaults does NOT work

In Xcode 6: NSUserDefaults does not work in devices simulators (iPhone 5, iPhone 6, etc, simulators). If you test on real devices, it works perfect. Someone know how to send this information to Apple? I have tried to contact Apple, but I have not…
Markus
  • 1,147
  • 16
  • 26
7
votes
1 answer

Where are user defaults plist files stored in iOS8?

I can't find preferences .plist file, because Preferences folder is empty. To get Library folder I use: println(NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]) Xcode 6 beta 5, iOS Simulator
ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
7
votes
1 answer

Override AppleLanguages in NSUserDefaults

If I override/alter the AppleLanguages in NSUserDefaults, iOS does not update the list anymore when the system language is changed. If I leave the list unchanged, the first object in the array will always be the system language, however, if I insert…
Jorn
  • 1,054
  • 9
  • 25
7
votes
5 answers

NSUserDefaults not storing values between app and custom keyboard in iOS 8

I'm trying to share data between my application and a custom keyboard extension. I've turned on App Groups in both the main application target and the custom keyboard target. In my main application, I add an object with the following: NSUserDefaults…
bdev
  • 2,060
  • 5
  • 24
  • 32
7
votes
1 answer

Is it safe to rely on NSUbiquitousKeyValueStore for storing essential data?

I learned that NSUbiquitousKeyValueStore is always available, also when no iCloud account is set up. This makes me believe I can safely store essential data in it, without keeping a copy in NSUserDefaults. However, in their documentation, Apple says…
Jonathan
  • 6,572
  • 1
  • 30
  • 46
7
votes
1 answer

What can cause NSUserDefaults to be cleared

I've been getting some odd reports for my app where the application settings stored into the NSUserDefaults is being cleared. The reports have all been on iOS 7s I know you can manually clear the NSUserDefaults by either uninstalling or making a…
loadedion
  • 2,217
  • 19
  • 41
7
votes
6 answers

NSUserDefaults not saving

I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called) if (![defaults objectForKey:@"obj"]) { difficultyLabel.text = @"Difficulty: Easy"; [defaults…
Lucas
  • 713
  • 2
  • 8
  • 19
7
votes
2 answers

NSUserDefaults gets reset

I have an ios app, and recently have been getting some reports from users about their settings getting reset. The settings are saved using NSUserDefaults. My question is, can the user defaults get corrupt/reset for some reason? A few notes about how…
am1987
  • 347
  • 3
  • 13
7
votes
1 answer

MKStoreKit crash on iOS 7 with SIGTRAP error

I have been over and over this live app crash log and cannot find the problem: 1 CoreFoundation _CFHash + 130 2 CoreFoundation CFBasicHashFindBucket + 724 3 CoreFoundation _CFDictionaryGetValue + 99 4 CoreFoundation …
SAHM
  • 4,078
  • 7
  • 41
  • 77
7
votes
2 answers

Is NSUserDefaults threadsafe

I know that documentation says that it is, and i know that this subject was already under discussion but I have an interesting stack result and I cant conclude anything else but that [NSUserDefaults standardUserDefaults] is not threadsafe. So I will…
AntonijoDev
  • 1,317
  • 14
  • 29
7
votes
1 answer

How to save LinkedIn Access Token using iOS SDK?

I am using LinkedIn in my iOS app. I want to save the access token for the future use. The token is of non property type which cannot be saved in NSUserDefaults directly. I tried using NSKeyedArchiver for this but I got the…
Imran
  • 1,715
  • 2
  • 20
  • 42