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
21
votes
2 answers

Attempt to insert non-property value Objective C

Hi l am trying to create a fourates lists from an restaurants Object, my application has a list of different restaurants, l want the ability for users to add favourate restaurants, and this code is not working - (IBAction)toggleFav:(id)sender { …
20
votes
3 answers

How to convert int to nsindexpath?

I am making a basic quiz application.The choices are in the form of a table view. If the user moves to a previous question, I want to show him his previously selected choice. I have stored the choice in NSUserDefaults. How do I convert this int…
Adam Young
  • 1,321
  • 4
  • 20
  • 36
20
votes
2 answers

Simple persistent storage in Swift

I have an array of objects each with a number of properties. Here is some sample data taken by looping through the array of objects: Name = Rent Default Value 750 This Months Estimate = 750 Sum Of This Months Actuals = 0 Risk Factor = 0.0 Monthly…
20
votes
5 answers

How do I find out the current keyboard used on iOS8?

You can get a list of the keyboards installed on the iOS device using: NSUserDefaults *userDeafaults = [NSUserDefaults standardUserDefaults]; NSDictionary * userDefaultsDict = [userDeafaults dictionaryRepresentation]; NSLog(@"%@",…
awolf
  • 1,862
  • 22
  • 29
20
votes
2 answers

UIWebView Load URL with parameters

I have an application that stores the user ID and code in NSUSERDEFAULTS I need to use these values in order to get UIWebView to visit url: www.mywebsite.com/check.php?id=(idhere)&code=(idhere). I have looked at some other topics but nothing has…
Jack Brown
  • 580
  • 3
  • 6
  • 20
19
votes
4 answers

Save CoreData-entities in NSUserDefaults

Imagine an CoreData entity (e.g. named searchEngine). NSManagedObjectContext manages some "instances" of this entity. The end-user is going to be able to select his "standard searchEngine" with a NSPopupButton. The selected object of NSPopupButton…
papr
  • 4,717
  • 5
  • 30
  • 38
19
votes
2 answers

Deleting App / NSUserDefaults data on macOS

I am from iOS dev background and writing my first MacOS app in Swift. On iOS, if I want to delete the app's NSUserdefaults, I would tap/hold the app icon on my device and delete it. On MacOS, however, I do not see my app icon in applications folder.…
Kashif
  • 4,642
  • 7
  • 44
  • 97
19
votes
4 answers

iOS 10, NSUserDefaults Does Not Work

I try to write/read values to/from [NSUserDefaults standardUserDefaults], but it seems not to work. My code is: [[NSUserDefaults standardUserDefaults] setObject:@"sampleString" forKey:@"sampleKey"]; [[NSUserDefaults standardUserDefaults]…
antonio
  • 722
  • 11
  • 22
19
votes
4 answers

iOS NSUserDefaults Watching the change of values for a single key

I have the following code aiming to catch the event of a NSUserDefaults value changing for a particular key. [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:SOME_NSSTRING_VARIABLE …
Sankar
  • 6,192
  • 12
  • 65
  • 89
18
votes
3 answers

NSUserDefaults Contains Value Or Not?

How to know whether NSUserDefaults contains any value?How to check whether its empty?
Aswathy Bose
  • 4,279
  • 4
  • 32
  • 44
18
votes
2 answers

Save list of CGPoints using NSUserDefaults

I have a bunch of CGPoints from a CCTMXLayer I want to save to NSUserDefaults but cannot seem to figure out an elegant way of doing so. Originally I was hoping to save an NSDictionary with an NSMutableSet for a value containing several NSValues…
Chris Daviduik
  • 336
  • 3
  • 10
18
votes
4 answers

UserDefaults is not saved with Swift

I'm trying to use the UserDefaults to persistently save a boolean value. This is my code : public static var isOffline = UserDefaults.standard.bool(forKey: "isOffline") { didSet { print("Saving isOffline flag which is now \(isOffline)") …
Andrea Mario Lufino
  • 7,921
  • 12
  • 47
  • 78
18
votes
4 answers

When and why should you use NSUserDefaults's synchronize() method?

So I've had a look at the apple documentation on the NSUserDefaults's synchronize() method. See below for reference: https://developer.apple.com/reference/foundation/userdefaults/1414005-synchronize The page currently reads: Because this method is…
James Stonehill
  • 1,125
  • 10
  • 22
18
votes
4 answers

Is it mandatory to call NSUserDefaults synchronize method?

Please, anyone, help me: Is calling NSUserDefaults's synchronize() method mandatory?. If I don't call it, what will happen? My application is working fine without it.
Balagurubaran
  • 549
  • 6
  • 18
18
votes
2 answers

Determine if user has enabled application's Safari content blocker extension

I'm working on a Safari Content Blocking extension. I intend to show setup instructions if the extension is disabled and to show settings if it is conversely enabled. How can I determine if the extension is enabled by the user? I've seen this method…
Ryan Brodie
  • 6,554
  • 8
  • 40
  • 57