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

Should I use core data to store some user preferences or save it in NSUserDefaults?

Currently, I'm developing an app that functionality heavily relies upon retrieved JSON data. Most of the data I'm planning to save into core data. However, not sure do I have to save all user related stuff (settings, favorites, twitter, Facebook and…
Centurion
  • 14,106
  • 31
  • 105
  • 197
8
votes
2 answers

Does NSUserDefaults get erased when an app gets updated?

In my App i am using NSUserDefaults to save some data. I have a doubt regarding this when i update the app in App Store, Will The Data in NSUserDefaults will remain same or it is removed.
kiri
  • 1,977
  • 5
  • 27
  • 55
8
votes
3 answers

How to use NSUbiquitousKeyValueStore and NSUserDefaults together

Documentation is not clear on how to use NSUbiquitousKeyValueStore with edge cases. If I want to set a value, I understand that I should set a value to both NSUserDefaults and NSUbiquitousKeyValueStore since iCloud could be disabled. However in my…
gcamp
  • 14,622
  • 4
  • 54
  • 85
8
votes
6 answers

IOS: store an array with NSUserDefault

I want to store an array with NSUserDefault, then, I put in applicationDidEnterBackground [[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"]; and in application didFinishLaunchingWithOption myArray= [[NSMutableArray alloc]…
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
8
votes
2 answers

Removing UserDefaults-generated plist file when running unit tests

I'm testing a class that depends on an instance of UserDefaults. In following this sample code found here, I create and setup the instance like so: override func setUp() { super.setUp() defaults = UserDefaults(suiteName: #file) …
WongWray
  • 2,414
  • 1
  • 20
  • 25
8
votes
3 answers

How to use NSUserDefaults to store an array of custom classes in Swift?

I have a custom class called Person that stores various attributes about someone when they enter information. class Person { // Person dictionary variable var name: String? var age: String? var html_url: String? init(json:…
Daniel Bramhall
  • 1,451
  • 4
  • 18
  • 24
8
votes
1 answer

iOS Swift Where to Store User Logged In Data or OAuth Token?

Things aren't as clear as they could be on the best practice to store logged in data on the users phone. Some suggest that data such as userID = 123 and loggedIn = true type data should be stored in the NSUSerDefaults data. Yet from my…
Michael Cropper
  • 872
  • 1
  • 10
  • 28
8
votes
1 answer

NSCoding with as NSString inside a object

My issue is then I retrieve my NSArray of Store objects, all my NSString properties are causing BadAccess errors. The int and double properties work fine! store.h @interface Store : NSObject { NSString *Name; NSString *Address; …
8
votes
3 answers

settings bundle not working on watchOS 2

This was NOT a problem on watchOS 1, but now on watchOS 2 I cannot read the values on the watch extension. According to Apple docs, it is possible. According to some people on this thread, it is possible. According to an Apple employee on this…
spybart
  • 2,583
  • 3
  • 22
  • 33
8
votes
1 answer

NSInvalidUnarchiveOperationException cannot decode object error in Apple Watch extension

I've got a user object that I need to store in NSUserDefaults and share with an iOS 8 extension app (Watchkit). In the main container app, I can encode and decode the object without any problem. However, when I try to retrieve the stored user object…
8
votes
4 answers

Save struct in class to NSUserDefaults using Swift

I have a class and inside the class is a (swift) array, based on a global struct. I want to save an array with this class to NSUserDefaults. This is my code: struct mystruct { var start : NSDate = NSDate() var stop : NSDate =…
Thomas
  • 1,468
  • 4
  • 14
  • 20
8
votes
5 answers

Save and Load Data on Today Extensions (iOS 8)

Is it possible to save and load data on Today Extension using NSUserDefaults? After closing the Notification Center, the widget behaves like an app which is terminated, so any data results lost. How could I solve this issue? This is my…
Massimo Piazza
  • 663
  • 3
  • 7
  • 21
8
votes
4 answers

NSKeyedArchiver/NSuserDefaults - saving a CGRect

My app involves a user being able to drag specific items such as volume sliders and UIImage views. My goal is to be able to save the locations of the items so that the user can not have to drag the items again after re-launch. Unfortunately, I…
Flafla2
  • 691
  • 2
  • 11
  • 21
8
votes
1 answer

Is the data stored using NSUserDefaults deleted when the app is updated?

Currently I'm creating an app that is storing data using NSUserDefaults. So when I upload v1 of the app to the app store and then make a new update for the app (v2) is the data stored in NSUsedDefaults deleted when the user updates to the new…
AFB
  • 550
  • 2
  • 8
  • 25
8
votes
1 answer

Why are NSUserDefaults not read after flat battery IOS7

I am using NSUserDefaults to store whether the app EULA and PP have been accepted (among other things) This works fine in general. I can start, exit then return to the app and it reads the value fine. I can kill the app and restart - reads the…
muldercnc
  • 421
  • 2
  • 10