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
Filter by
Sorted by
Tagged with
8 votes
4 answers
11k views

NSUserDefaults. setValue works, Not setBool

I trying to store some settings in NSUserDefaults, but It seems that the app won't store the setBool values. This works: [[NSUserDefaults standardUserDefaults] setValue: @"hello" forKey: @"test"]; ...
BlackMouse's user avatar
  • 4,514
7 votes
5 answers
7k views

Save a tuple in NSUserDefaults

I'm using a tuple to store something like this. var accessLavels: (hasInventoryAccess: Bool, hasPayrolAccess: Bool) accessLavels = (hasInventoryAccess: true, hasPayrolAccess: false) Now I want to ...
Isuru's user avatar
  • 31k
7 votes
2 answers
3k views

Delete all my NSUserDefaults that start with a certain word

Is there a way for me to "walk" through a list of all the NSUserDefaults in my iPhone app, and only delete certain ones? For example, I'd like to get all the key names that start with a certain word. ...
Patricia's user avatar
  • 309
7 votes
3 answers
2k views

How can I remove value that was previously registered via [NSUserDefaults registerDefaults:] call

I have bunch of preference values registered via [NSUserDefaults registerDefaults:] call on application startup. I need to replace them at some stage with new ones but new values scope (keys set) is ...
macwasik's user avatar
7 votes
6 answers
14k views

NSUserDefaults not saving

I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called) if (![defaults objectForKey:@"obj"]) { ...
Lucas's user avatar
  • 713
6 votes
4 answers
5k views

Reading NSUserDefaults in watchOS 2 (I know App Groups doesn't work)

Apple documentation says "Also, iOS automatically forwards a read-only copy of your iOS app’s preferences to Apple Watch. Your WatchKit extension can read those preferences using an NSUserDefaults ...
victorpulak's user avatar
6 votes
4 answers
6k views

Need to archive CLLocation data

I have an array of CLLocation data that I would like to archive. Should the NSUserDefaults system be used? Otherwise, how best to archive the CLLocation data?
devonsmith's user avatar
5 votes
3 answers
3k views

Detecting the first ever run of an app

I am creating an app in which I have to create a plist when the app launches for the first time. I'm later going to use the plist to store details a user later inputs. How can I detect the first ...
theNoobProgrammer's user avatar
5 votes
2 answers
3k views

Saving an image array with UserDefaults

I have an app where the user takes a picture and once the picture is taken it should be saved to UserDefaults. I keep getting this error: "cannot invoke 'setObject' with an argument list of type '(...
user3462448's user avatar
5 votes
2 answers
8k views

iOS - Attempt to insert non-property list object NSDictionary in NSUserDefaults

In my app, I need to save my custom User object NSDictionary in my NSUserDefaults. I attempt this with the following code: NSDictionary *userObjectDictionary = response[@"user"]; NSLog(@"USER OBJECT:\...
Rafi's user avatar
  • 1,922
5 votes
7 answers
1k views

Cannot set NSUserDefaults field

I have the following code in my initialization (first time) of my app: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *uid=@"1"; [defaults setObject:uid forKey:@"init_val"]...
mlewis54's user avatar
  • 2,370
5 votes
1 answer
3k views

Why use registerDefaults: instead of setValue:forKey:?

When I'm setting up the default preferences for my app, I'm doing the following: 1) Reading Root.plist from inside Settings.bundle into a dictionary. 2) I test if a preference is set, and if not I'm ...
gabrielk's user avatar
  • 563
5 votes
1 answer
1k views

Persist a MPMediaItemCollection Object Using NSUserDefaults

How do you persist a MPMediaItemCollection object using NSUserDefaults? The MPMediaItemCollection object is a single song selected from the iPod. I have been struggling with this for hours! Anyone ...
Adam Waite's user avatar
  • 19.2k
5 votes
1 answer
2k views

Separate Settings in Universal iOS App?

I'm working on an universal iOS app, but a few user settings don't make as much sense on the iPad. Can I specify a separate Settings.bundle or Root.plist for use on the iPad?
nschum's user avatar
  • 15.4k
4 votes
2 answers
2k views

Programmatic Equivalent of "defaults write" command, e.g., how to use NSUserDefaults?

Trying programmatically do what the 'defaults write' command does in OS X. I can't seem to figure out how to get the correct preferences dictionary for the domain I'm looking for. I can get some ...
RibaldEddie's user avatar
  • 5,136
4 votes
2 answers
693 views

iOS - setObject vs. Synchronize

Newbie question. If I set an object into NSUserDefault do I also need to Synchronize to be sure the object goes back into NSUserDefault database permanently? I guess what I am asking is, is "setobject"...
user avatar
4 votes
3 answers
4k views

How can I store an array of custom objects (Goals)

How can I store an array of objects of type Goal which I have created in NSUserDefaults? (in swift) Here is the code: func saveGoalList ( newGoalList : [Goal] ){ let updatedGoalList = ...
CaptainCOOLGUY's user avatar
4 votes
2 answers
3k views

force reset NSUserDefault on iPhone App upgrade

i want to force reset to NSUserDefault whenever user update my app. why i need this because every update include some new information abt user. as some info (token) already present in NSUserDefault my ...
Nnp's user avatar
  • 1,853
4 votes
5 answers
9k views

Pass data between UITabBarController views

I have searched for an entire day for a simple example on this and haven't found it yet. I am working on an app and I want to make an API call on the initial load and populate some variables that will ...
Donovan's user avatar
  • 926
3 votes
2 answers
3k views

How to save and retrieve NSObject class using NSUserDafaults in iOS

Hi I want to save and retrieve NSObject class using NSUserDefaults for that I wrote below code but I am getting exception like below Terminating app due to uncaught exception '...
AbhiRam's user avatar
  • 2,063
3 votes
4 answers
939 views

See NSUserDefaults file content

Is there any way I can see the content of NSUserDefaults? I'm able to open the plist file using "pico" from the terminal, but it shows weird characters, I can't actually see the content file content. ...
Rafael's user avatar
  • 1,151
3 votes
2 answers
5k views

how can store custom objects in NSUserDefaults

I apologize for duplicate Question . I am new in ios . I want to store custom objects in userdefaults. I am using objective-c . Thanks in advance
hdkumar's user avatar
  • 49
3 votes
5 answers
10k views

NSUserDefaults Not Saving TextField Text (Swift)

I'm trying to create a game with Swift, and I want to add the ability to create a username, which will be saved in NSUserDefaults. This is my code: println("Textfield Text: \(usernameTextfield....
nanothread's user avatar
3 votes
1 answer
2k views

Updating & changing settings plist files with new versions of an app

I've got a default settings plist file in the resources folder of my app, and on the first launch that gets copied to the documents folder. In successive versions of the app, how can I merge the ...
Michael Waterfall's user avatar
3 votes
4 answers
7k views

How to save integer value to NSuserDefault like sqlite?

I want to save and retrieve value in NSUserDefault. I am saving and retrieving Value sucessfully. But when I go cak Homepage and again come in my class The value is not stored and all the process done ...
Nisha Singh's user avatar
3 votes
2 answers
2k views

NSUserDefault with App Group is not working in iOS 8 Beta3

I have to save Boolean Value to NSUserDefault in my App with custom keyboard extension and share with App Group. My Code is worked in iOS 8 Beta1. self.defaults = [NSUserDefaults ...
Fire Fist's user avatar
  • 7,052
3 votes
1 answer
944 views

Save MKPolyline as NSData in NSUserDefaults

My iOS application needs to store an MKPolyline inside of an NSUserDefault. I've been doing a lot of research, and I now know that: NSUserDefaults are a subclass of NSCoder MKPolyline is not a ...
Sam Spencer's user avatar
  • 8,577
3 votes
4 answers
122 views

Error when trying to save to NSUserdefaults

I have a table which works in the following way. If a row is selected, an amount corresponding to the selected row is added to var total, a checkmark is added. If it is deselected, the amount will be ...
bibscy's user avatar
  • 2,678
3 votes
2 answers
256 views

Storing object on iOS - best solution?

I'm building an app for a blog where a user can save their favorite posts. When they do, I want to store my object which contains: the post's URL, title and image URL. Should I go for UserDefaults (...
sf89's user avatar
  • 5,148
3 votes
1 answer
7k views

Why does NSUserDefaults fail to save NSMutableDictionary?

I’m trying to save a NSMutableDictionary with NSUserDefaults. I read many posts on the topic in stackoverflow... I also found one option that worked; however unfortunately it worked only once and then ...
user1940136's user avatar
3 votes
3 answers
7k views

Xcode iOS: check if user is logged in and show different views if not

I'm coding an app where a logged in user has got a couple of extra functionalities than a non logged in user. Basically, I have more or less 5 tabs. When I launch the app, the user immediately gets ...
el-flor's user avatar
  • 1,466
3 votes
3 answers
4k views

How to remove all data by a suite name from UserDefaults in Swift?

I have created user defaults with names below, let prefs1 = UserDefaults.init(suiteName: "UserAccount") let prefs2 = UserDefaults.init(suiteName: "UserInfo") Then I have added some values to those ...
Sazzad Hissain Khan's user avatar
3 votes
2 answers
7k views

Swift optionals - warning on conditional cast from 'x' to 'x' always succeeds

I was wondering if there is a way to turn off/avoid 'yellow' warnings in xcode on if let...NSUserDefaults constructs where the key is of a known value. For example: if let x = NSUserDefaults....
zevij's user avatar
  • 2,436
2 votes
2 answers
4k views

Data persistence through NSUserDefaults

Is data persisted in NSUserDefaults between app launches? I want some small data to be persisted even if I quit and relaunch the app.
Abhinav's user avatar
  • 38k
2 votes
3 answers
5k views

IPhone SDK Default NSUserDefaults

I have set up the user defaults to record a integer for a UISlider, the problem is that, if the user has only just installed the app then the integer is zero or NULL. Is there a way to detect if it = ...
Harry's user avatar
  • 75
2 votes
2 answers
3k views

Specifically detailing what defaults have changed on NSUserDefaultsDidChangeNotification

I'm starting to get into the inner sanctum of NSUserDefaults to the point where I can now successfully intercept an NSUserDefaultsDidChangeNotification notification using a supplied selector plus ...
VectorVictor's user avatar
2 votes
1 answer
1k views

The proper way to delete rows from UITableView and update array from NSUserDefaults in Swift / iOS

What is the proper way to delete rows from UITableView and update array from NSUserDefaults? In the following example I'm reading an array from NSUserDefaultsand feeding a UITableView with its ...
fs_tigre's user avatar
  • 11k
2 votes
2 answers
820 views

How to set response data into TodayExtenstion widget

Trying to access response data from service to show into TodayExtenstion Widget import Foundation struct MarketIndex:Codable { let indicesName: String let indicesValue: String let ...
kiran's user avatar
  • 4,349
2 votes
2 answers
3k views

iPhone and NSUserDefaults

In my viewWillLoad: method I'm currently doing something along these lines: - (void)viewWillAppear:(BOOL)animated { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ( [...
Alasdair Allan's user avatar
2 votes
2 answers
1k views

How to save a Array with (Multiple Types) in NSUserDefaults

This is pretty simple but can't seem to find the correct information to solve saving an array like this in User Defaults. It says it's not a property that NSUser Defaults Excepts. Code: var ...
Hunter's user avatar
  • 1,361
2 votes
1 answer
1k views

Objective-C NSUserDefaults caching prevents another app from accurately reading changes

I have one application that sets preferences. It uses those prefs, and so does another application. When I use the following code in the second application, it reads the preferences correctly once. ...
Adam's user avatar
  • 911
2 votes
2 answers
3k views

NSUserDefaults vs sqlite3

I have a small iPhone app that stores a list of objects. The user can add and remove objects, but this list will remain fairly small (most users would have 10-30 objects). NSUserDefaults seems much ...
respectTheCode's user avatar
1 vote
2 answers
6k views

How to save struct to NSUserDefaults in Swift 2.0

I have a struct named Jarand I would like to save an array of them to NSUserDefaults. Here is the jar struct code: struct Jar { let name: String let amount: Int init(name: String, ...
Ryan Westcott's user avatar
1 vote
2 answers
1k views

Is there a better way to save a custom class to NSUserDefaults than encoding and decoding everything with NSCoder?

My current class has around 50 lines just encoding and decoding variables in order for my class to be NSUserDefaults compatible. Is there a better way to handle this? Example: init(coder aDecoder: ...
Arch's user avatar
  • 127
1 vote
2 answers
978 views

iPhone inputting NSUserDefaults into a UITextField

I am writing a program where I where the first time a user runs it - they will have to fill out about 10 different UITextFields. I am trying to save the fields so that on subsequent runs of the ...
startuprob's user avatar
  • 1,917
1 vote
2 answers
722 views

Store Custom Objects in NSUserDefaults

I am trying to store a custom objects as follows, but I am getting an error. // store data NSMutableArray *archiveArray = [NSMutableArray arrayWithCapacity:pOrderElements.count]; for (id ...
casillas's user avatar
  • 16.6k
1 vote
1 answer
9k views

How to resolve "Initializer for conditional binding must have Optional type, not 'Int'"?

I've seen examples of how to resolve this error but I can't get it to work in my case. Initializer for conditional binding must have Optional type, not 'Int' Shouldn't employeeCount be optional ...
4thSpace's user avatar
  • 44.1k
1 vote
1 answer
2k views

Saving highscores with NSUserDefaults

I'm trying to save the highscore of my game. I'm trying to do this via NSUserDefaults. This is the code I'm using: //To save highest score var highestScore:Int = 20 NSUserDefaults....
Raul Gonzalez's user avatar
1 vote
1 answer
840 views

How to set Dictionary in NSUserDefault in swift?

I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that: var myDic: NSMutableDictionary = [:] myDic = [1:2] NSUserDefaults....
Sam's user avatar
  • 869
1 vote
2 answers
3k views

NSUserDefaults Settings Bundle Plist

I have an app that checks for a file upon load from the appDelegate's appDidFinishLoading method using a url value that I supposedly store in the NSUserDefaults Settings Root Plist: NSString *pathStr ...
marciokoko's user avatar
  • 4,986

1 2 3
4
5
10