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

Binding a text field to Shared User defaults controller doesn't use null value

I set the text field to bind with a values controller key, a keypath of spacesPerTab, and setting 4 as the placeholder values. But when executing it, the text field displays nothing. This works for checkboxes.
Jeffrey Drake
  • 805
  • 10
  • 26
1
vote
1 answer

Issues with displaying array of strings in Watch App table

I've been having issues with passing an array of strings between a containing app and the watch app and I had posted a question earlier about receiving the error String is not identical to AnyObject - 'String' is not identical to 'AnyObject'…
user3746428
  • 11,047
  • 20
  • 81
  • 137
1
vote
2 answers

Swift - saving and retrieving images from userDefaults

I'm trying to save images retrieved from Parse.com like this: let userImageFile = object["Image"] as PFFile userImageFile.getDataInBackgroundWithBlock { (imageData: NSData!, error:…
martin
  • 1,894
  • 4
  • 37
  • 69
1
vote
3 answers

Saving And Loading Up A Highscore In Swift Using NSUserDefaults

I am having some problems while attempting to compare my score and highscore to see which one is bigger and then save it. I think the problem lies in the comparison and saving of the highscore and score. Help would be greatly…
hAPPy
  • 69
  • 5
1
vote
2 answers

Save checkmark in NSUserDefaults - dynamic TableView

Solution!! Thanks Josh for all the patience :D So the code in the initial question always ticks the selected cell and deselects a previously selected cell without saving anything to the NSUserDefaults. After a lot of help from Josh the new code…
1
vote
2 answers

Saving selection using AKPickerView

Project desc. I have a left drawer with a table selection with many options. One of which is a settings option. Inside the settings option is a table view. I have embedded AKPickerView inside once of the cells. The AKPickerView is giving me the…
ChrisOSX
  • 724
  • 2
  • 11
  • 28
1
vote
1 answer

save data depending on passed value in swift

I'm trying to save time taken to complete each level. so im looking for a better way to save data, i have 100 variables for all levels i.e, leveltime1, levetime2....and so on..leveltime100 I have this code which is not working var leveltime : [Int]…
user528432
  • 411
  • 2
  • 5
  • 18
1
vote
1 answer

Getting unexpectedly found nil while unwrapping an Optional value

I am very new to programming, and I have been looking online for a few days now trying to address this issue that I have been have with my Swift programming. I am new to all of this; and, I have tried my earnest to try and find a solution on my own.…
George Lee
  • 814
  • 18
  • 34
1
vote
3 answers

Saving score with NSUserDefaults: UInt8 not convertible to Int8

I'm creating a simple game. if the player loses i want his current score to be compared with the best score saved as persistent storage as NSUserDefault. i keep on getting "UInt8 is not convertible to Int8" this is the code…
Wassim Seifeddine
  • 1,002
  • 12
  • 25
1
vote
1 answer

How to write an array to NSUserDefaults in Swift

I'm trying to write the contents of an array to NSUserDefaults, but the app hangs when I call setObject:withKey with the array as the object. Here's the relevant code: class Contact: NSObject { var name:String = "" var number:String =…
Epsilon
  • 1,016
  • 1
  • 6
  • 15
1
vote
1 answer

Changing main view controller background color from value in NSUserDefaults

I have two view controllers, one is the main one and the second is a settings view controller. I have buttons on the settings VC that is set to change the background color of the settings VC and the main one. It stores the color in NSUserDefaults…
ChallengerGuy
  • 2,385
  • 6
  • 27
  • 43
1
vote
1 answer

Extracting time from NSDate in Swift

Right now I have an NSDate set to be stored in NSUserDefaults. When I go to retrieve that date I want to extract and format the time. Can anyone tell me how to do this in Swift? I have: punchTimes.setObject(NSDate(), forKey:…
Leighton
  • 6,559
  • 7
  • 21
  • 28
1
vote
1 answer

NSUserDefaults in Swift won't save my data the way my code currently is. What's my issue?

This is my code on the view controller with the total score: import UIKit var playerName = "" var totalScore = 0 var bestPlayer = "Taipan" var highScore = 100 var myNumber: NSInteger = highScore var myName: NSString = bestPlayer class StartVC:…
1
vote
1 answer

Objects saved with NSKeyedArchiver and loaded back are nil

I save a custom object Bottle with the following code class Bottle: NSObject, NSCoding { let id: String! let title: String! let year: Int! let icon: UIImage! init(id: String, title: String, year: Int, icon: UIImage) { …
magohamote
  • 1,484
  • 1
  • 17
  • 29
1
vote
3 answers

iOS 8 simulator not clearing user defaults on deleting the app in Xcode 6.0?

The user defaults are not cleared on deleting an app in XCode 6 iOS 8 simulator. The user defaults are cleared only on resetting the simulator. In iOS 7 simulator, this is not a problem at all. Any other solution rather than resetting the simulator?