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
18
votes
5 answers

Can I use NSUserDefaults with tvOS?

The App Programming Guide for tvOS briefly states that There is no persistent local storage for apps on Apple TV. This means that every app developed for the new Apple TV must be able to store data in iCloud and retrieve it in a way that provides a…
jtbandes
  • 115,675
  • 35
  • 233
  • 266
18
votes
3 answers

Changing language on the fly in swift

Now I know that apple does not recommend this. In general, you should not change the iOS system language (via use of the AppleLanguages pref key) from within your application. This goes against the basic iOS user model for switching languages in…
modesitt
  • 7,052
  • 2
  • 34
  • 64
18
votes
1 answer

Expected Declaration Error using Swift

I'm trying to pass the boolean value of a UISwitch to another class using NSUserDefaults. For some reason, in the class that contains the switches, the if statements that are supposed to set the value to NSUserDefaults cannot read the switch…
18
votes
2 answers

NSUserDefaults initWithSuiteName persisting after deleting app

I have an issue where if I store any data using [[NSUserDefaults alloc] initWithSuiteName:SUITE_NAME]] the data persists even after deleting the app. Is this supposed to happen?
thisiscrazy4
  • 1,905
  • 8
  • 35
  • 58
18
votes
3 answers

Why won't app groups work inside my WatchKit extension?

I've seen all the other posts of SO about sharing NSUserDefaults data between host apps and app extensions, but mine still doesn't work. Here's everything I've done: Enable App Groups on Xcode's "Capabilities" tab for the extension and host…
18
votes
5 answers

NSUserDefaults or keychain is better to save username and password in iPhone app

In my iphone app there is some confidential data like username, password and some urls to a webservice. Which one is better NSUserdefaults or keychain. Somebody says NSUserdefaults is insecure. Why it is insecure? and can any one give the pros and…
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
17
votes
6 answers

insert object in an NSMutableArray saved with NSUserDefaults

I have an NSMutableArray saved with NSUserDefaults. This array is my "favourite" items that the user can saves, so when i want to add one item, i need to read the array (from NSuserDefault) and save in the first free position. I'm using this method…
JAA
  • 1,024
  • 3
  • 20
  • 34
17
votes
3 answers

How to test with NSUserDefaults?

In most of my classes that work with defaults I make the defaults object settable: @property(retain) NSUserDefaults *defaults; This is supposed to make testing easier: // In a nearby test class: - (void) setUp { [super setUp]; …
zoul
  • 102,279
  • 44
  • 260
  • 354
17
votes
2 answers

iOS 10 with XCode 8 GM caused NSUserDefaults to intermittently not work

NOTE: I have seen many other posts on Stack Overflow about NSUserDefaults being renamed to UserDefaults in Swift or not working on simulator until a restart. This is not a duplicate by anyway. Many of the questions SO is tagging against is from 4…
17
votes
3 answers

Swift: Insert Alert Box with Text Input (and Store Text Input )

In one of my viewController, I want to make an alert box appear that prompts the user to type this information.Then, I want the user to store this input using NSUserDefaults. How can I achieve this? Thank you in advance!
l-spark
  • 871
  • 2
  • 10
  • 25
17
votes
3 answers

Storing Int64 in UserDefaults

I define my dictionary like this: var teamsData = Dictionary>() Then, I am trying to store it in userdefaults: NSUserDefaults.standardUserDefaults().setObject(teamsData, forKey: "teamsData") but it throws the error:…
Kashif
  • 4,642
  • 7
  • 44
  • 97
17
votes
9 answers

MKMapView show incorrectly saved region

I'm saving map region into user defaults when my iPhone app is closing like this: MKCoordinateRegion region = mapView.region; [[NSUserDefaults standardUserDefaults] setDouble:region.center.latitude…
17
votes
2 answers

Working with data in iOS Apps (What to choose? NSData, CoreData, sqlite, PList, NSUserDefaults)

when I develop an iPhone App (Time Tracker, ToDoList etc) I never know whats the best way to deal with the data. Once I used a plist, next time sqlite or CoreData. How do you decide whats the best for your project? (Only talking about data…
user1010563
16
votes
3 answers

how to get XCode to add build date & time to Info.plist file

Finally... after a couple years of watching and a month of participating, I have a chance to ask you guys a question of my own. My boss doesn't trust me (or any process) to increment a build number, he also wants to have a build date & time baked…
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
16
votes
2 answers

Are values stored in NSUserDefaults removed when the app that put them there is uninstalled?

If I put a token (a string) into NSUserDefaults, lets say as a paramter passed to a REST API that is used by the app, and the app is uninstalled, will the string remain on the device?
barfoon
  • 27,481
  • 26
  • 92
  • 138