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
1
vote
0 answers

How do I persist a dictionary if the object is an item from a class that stores three values in Swift?

I'm trying to store a mutable (I believe that shouldn't make a difference, as it will be immutable once it's retrieved from NSUserDefaults) dictionary with NSUserDefaults, that has objects from a class which holds two string values and one boolean…
Jerry
  • 11
  • 3
1
vote
1 answer

Swift: EXC_BAD_ACCESS when observing NSUserDefaults

I'm writing an iOS app using Swift and want to get notified of NSUserDefault changes. When I register an observer and try to modify the NSUserDefault data afterwards, I always get the following runtime error: EXC_BAD_ACCESS I've created a little…
Felix
  • 776
  • 8
  • 16
1
vote
2 answers

Problems with storing UISwitch state

I have a setting in my app that I am having issues retaining the state of. Basically, the UISwitch is on by default, however when updating my app to a newer version, it seems to switch off. I figured out that if the user has opened the settings menu…
user3746428
  • 11,047
  • 20
  • 81
  • 137
1
vote
2 answers

Issue unwrapping string from NSUserDefaults

I am trying to get a value from NSUserDefaults and I am trying to set a variable to be this. The problem is that I am unsure about how I unwrap it? This is my code: var defaults = NSUserDefaults(suiteName: "group.AffordIt") …
user3746428
  • 11,047
  • 20
  • 81
  • 137
1
vote
1 answer

Issue with NSUserDefaults Class

I am following THIS tutorial and at 09:42 He add NSUserDefaults call this way : But when I try to search this call I got Like this : It is removed in xcode_6.1_beta_2.1? When I try to written It : var name = AnyObject?{ get { return…
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
1
vote
1 answer

Save tag of Button with NSUserDefaults

Hello everyone i have a problem with save tag of button when i click: - (IBAction)addButtonSeconds:(id)sender { if ([sender tag] == 1) { NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; [standardUserDefaults…
Tcacenco Daniel
  • 445
  • 7
  • 17
1
vote
2 answers

objectForKey returns nil for NSUserDefaults in Swift

I am using the following code to set a value into NSUserDefaults using Swift. Here is my code: let key = "ticker" let currencyTickerData = [key:"USD"] NSUserDefaults.standardUserDefaults().setObject(currencyTickerData, forKey:…
1
vote
1 answer

NSUserDefaults always returns 0, in Simulator and Device

I have a settings bundle in my iPhone app, with the following PList: Type: PSMultiValueSpecifier Title: Within (Kilometres) DefaultValue: Number: 1 Titles: Array: Item 1: Number: 1 Item 2: Number: 2 Values: Array: Item 1: Number: 1 …
joec
  • 3,533
  • 10
  • 60
  • 89
1
vote
2 answers

NSUserDefaults - Saving and retrieving "High Scores"

I am just learning to program and doing some SWIFT tutorials. I have done as much research as I could but seem to be missing some critical aspect. I have a simple game and when a player dies I want to check their score against the previously saved…
Frankeex
  • 449
  • 3
  • 20
1
vote
3 answers

How to store UISegmentedControle state in NSUserdefaults

The problem is when de selectedSegmentIndex is unselected: "UISegmentedControlNoSegment" alias "-1". The other states (0, 1, 2 , etc.), I can store as Integers and retrieve with carTypeSegmentedControl.selectedSegmentIndex = [defaults…
Chrizzz
  • 11
  • 1
1
vote
1 answer

How to reset high score for NSUserDefaults in SpriteKit with Swift

I have set a high score using NSUserDefaults where if the object makes contact with a block, the game ends. If the score is greater than the high score, it updates the high score with the new value. How would I reset the high score back to zero…
PoisonedApps
  • 716
  • 8
  • 21
1
vote
1 answer

iOS8 custom keyboard accessing user defaults without requesting open access

I'm implementing a custom keyboard for iOS8. I have a containing app that sets a few keyboard specific values to NSUserDefaults so that the keyboard can read from them. This works fine, however I must set requestsOpenAccess to yes to get this…
Alec
  • 1,247
  • 2
  • 9
  • 9
1
vote
2 answers

Clearing NSUserDefaults database programmatically between uninstall/re-install of an app

Goal: Cleaning an app's NSUserDefaults after the app has been uninstalled. Conversely, on re-install of an app, having it ignore any previous NSUserDefaults that might have been stored. That is, being able to detect that those NSUserDefaults belong…
idStar
  • 10,674
  • 9
  • 54
  • 57
1
vote
1 answer

NSUserDefaults "Pause" / Crash on iOS8

Ok, so I launched an app last week before iOS8 came out. Everything was working fine in iOS7 and below. But now since people have updated to iOS8 my app is pausing/crashing for no reason. I came to terms that it is when I set an NSMutableArray to…
DrRocker
  • 655
  • 1
  • 7
  • 14
1
vote
1 answer

Adding KVO to a Settings bundle

I’ve attempted to add KVO to my NSUserDefaults to watch for a value changing in Settings. I’ve added a breakpoint to my observeValueForKeyPath:object:change:context method but it’s never called. Here’s my code: override init() { super.init() …
Adam Carter
  • 4,741
  • 5
  • 42
  • 103