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

NSUserDefaults and iOS framework / library

I have recently been building an app using [NSUserDefaults standartdUserDefaults] to store locally various information (regarding the session, user preferences, etc). Now I am exporting a subpart of my project as an iOS framework (the goal is to…
Romain Dorange
  • 831
  • 1
  • 10
  • 23
13
votes
6 answers

App crashes when storing NSArray in NSUserDefaults

I couldn't store an NSArray in NsUserDefaults. The app gets crashed in this line [savedData setObject:jsonValue forKey:@"JSONDATA"]; Below is my code. and i have mention my log error below NSArray *jsonValue =[NSJSONSerialization…
iworld
  • 345
  • 1
  • 4
  • 17
13
votes
3 answers

Deciding to use Core Data or NSUserDefaults

I have a feature on my app that allows users to invite their friends (via facebook, or friends in their address book). Most people will have < 5K friends with some people having more (maybe a max of like 10K friends?). I want to keep track of the…
Atul Bhatia
  • 1,633
  • 5
  • 25
  • 50
13
votes
2 answers

iOS UILocalNotification set to fire once every day, once every two days, and only on Sundays

I'm trying to use a settings bundle to schedule a UILocalNotification. In settings, you can choose if you want the notifications to come daily (1/day), 1 every 2 days, only on Sundays or never. Here is the code I used (this is all in…
George Ciobanu
  • 655
  • 2
  • 6
  • 24
13
votes
3 answers

Can users modify NSUserDefaults key values in an iOS app?

I have a question about security. I am making an iOS app with in app purchase following this tutorial, and I store what products were bought in NSUserDefaults. That's why I wonder : Can a user with a jailbroken device modify NSUserDefaults key and…
darksider
  • 1,030
  • 2
  • 14
  • 20
12
votes
3 answers

Accessing NSUserDefaults Often

During a logic process in my app, I need to access the user preferences frequently, and a bunch of times 10~15 to determine what needs to be processed and how. May this question is not about performance, but about doing it correctly. Currently I'm…
sidyll
  • 57,726
  • 14
  • 108
  • 151
12
votes
4 answers

Swift: Natively Detect if App has Crashed

I have searched around, but have yet to find an answer that doesn't direct me towards a 3rd party service. I do not need anything intricate, just to save a value in NSUserDefaults so when the app opens next, I can display an alert saying the app has…
zennox
  • 624
  • 1
  • 8
  • 19
12
votes
1 answer

Cannot access NSUserDefaults using app groups one to another

I'm working on an app and a widget that the widget needs to get data from app. I've used the following codes to read and write on NSUserDefaults. And also I used $(PRODUCT_BUNDLE_IDENTIFIER).widget for widget and $(PRODUCT_BUNDLE_IDENTIFIER)…
do it better
  • 4,627
  • 6
  • 25
  • 41
12
votes
6 answers

Saving bool to NSUserDefaults and using it in a if statement using Swift

I am struggling to figure out how to do an if statement with a bool saved to NSUserDefaults using Swift. I believe I know how to save the bool to NSUserDefaults but a confirmation in that would be greatly appreciated. This is the Objective-C code I…
Emmanuel Amaro
  • 157
  • 1
  • 1
  • 8
12
votes
1 answer

When the app is deleted what happens to the values stored in NSUserDefaults?

I have a little question regarding NSUserDefaults. When the application is deleted, what happens to the values stored in the NSUserDefaults? Do they get deleted as well? When I remove a app and reinstall it from the app store the previous…
user3568907
  • 337
  • 1
  • 3
  • 5
11
votes
3 answers

NSUserDefaults.StandardUserDefaults - saving and retrieving a Dictionary

Would you guys help me? I found how to save and retrieve simple objects to use them as app settings. NSUserDefaults.StandardUserDefaults.SetString("testUser","username"); NSUserDefaults.StandardUserDefaults.Init(); //Although it's strange that you…
iLemming
  • 34,477
  • 60
  • 195
  • 309
11
votes
4 answers

Storing data to NSUserDefaults

In my iPhone app, I have a class called Contact which consists of an ABRecordRef to serve as a reference to a particular contact. I need to store groups of these contacts in NSUserDefaults, but things aren't working out so well since Contact is a…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
11
votes
1 answer

Trouble Replacing CloudKit Records

I get the fatal error: "Could not cast value of type 'NSTaggedPointerString' to 'NSData'" on the line "if (NSKeyedUnarchiver.unarchiveObject(with: loadedData as! Data) as? CKRecord) != nil". There is another fatal error:"Attempt to set a…
Steve
  • 1,121
  • 1
  • 12
  • 32
11
votes
1 answer

How To Check If User Has Already Made In-App Purchase? To Determine Their Access Level/Rights

I have a simple app, with one non-consumable in-app purchase option. From my initial view controller I have a single 'enter' button. This button will send a 'free' user (has not made non-consumable purchase) to one TabBarController "A" and series of…
11
votes
2 answers

How do I save a UIColor with UserDefaults?

I'm trying to program my code so that if the user presses the Night Button the background will turn black and stay black if the user closes the app. (Same goes for day mode.) Please note: I already coded buttons and when they press it, all of the…