FAQ Database Discussion Community


How do I ensure that the text entered into a UIAlertview transforms the text of a UIButton and STAYS that way after exiting and reentering the app

ios,objective-c,uibutton,constraints,nsuserdefaults
TL;DR : Open iOS app Enter a promo code Close app Open app Actual Results: Promo code box is out of wack (see images) Expected Results: Promo code should still be displayed So I've got a UIButton whose text keeps changing after the user clicks on it and exits and...

'anyObject' is not convertible to 'Dictionary]'

swift,dictionary,nsuserdefaults
Hi I want to get an object type dictionary by using NSUserDefaut : var favoritePlace = NSUserDefaults.standardUserDefaults().objectForKey("savePlace")! as [Dictionary] but i get the error 'anyObject' is not convertible to 'Dictionary]' i also try : var favoritePlace = NSUserDefaults.standardUserDefaults().objectForKey("savePlace")! as [Dictionary<String, String>()] but it's not work, too. Anyone know how can...

Saving Favorites to NSUserDefaults

ios,objective-c,nsuserdefaults
I have an app that displays posts from a website. I'm trying to add the ability for the user to save their favorite posts using NSUserDefaults. I need to save the title and url for each post the user wants to save as a favorite so I can display the...

How to retrieve data from NSUserDefaults?

ios,swift,audio,nsuserdefaults,mpmediaitemcollection
currently, I try make an music playlist application. I try to save and retrieve playlist data from NSUserDefaults. I have no problem when saving the data but I got an error when retrieving data. I got: Terminating app due to uncaught exception 'MPMediaItemCollectionInitException', reason: '-init is not supported, use -initWithItems:...

How to save an array of objects to NSUserDefault with swift?

ios,swift,nsuserdefaults
this is a class Place I defined: class Place: NSObject { var latitude: Double var longitude: Double init(lat: Double, lng: Double, name: String){ self.latitude = lat self.longitude = lng } required init(coder aDecoder: NSCoder) { self.latitude = aDecoder.decodeDoubleForKey("latitude") self.longitude = aDecoder.decodeDoubleForKey("longitude") } func encodeWithCoder(aCoder: NSCoder!) { aCoder.encodeObject(latitude, forKey: "latitude") aCoder.encodeObject(longitude,...

Can't sync NSUserDefaults with apple Watch

ios,objective-c,nsuserdefaults,apple-watch
I need to pass 2 doubles to apple watch, for this purposes I set app groups in extension and main app, next: main app: groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.XXXXX"]; [groupDefaults setDouble:pitchDelta forKey:@"pitch_delta"]; [groupDefaults setDouble:rollDelta forKey:@"roll_delta"]; [groupDefaults synchronize]; extension: groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.XXXXX"]; double pitchDelta = [groupDefaults doubleForKey:@"pitch_delta"]; double rollDelta...

How do you store big objects using NSUserDefaults efficiently? [closed]

objective-c,nsuserdefaults,nsobject
How do you store big objects using NSUserDefaults efficiently? Any help will be appreciated. Thanks!

Unarchive NSData back to NSColor in swift

osx,swift,nsuserdefaults,nsdata,nscolor
I have archived an NSColor to store it in NSUserDefaults: var data = NSArchiver.archivedDataWithRootObject(NSColor.redColor()) storage.setObject(data, forKey: "color") storage.synchronize() But now I need to get the color back from NSData, I have no idea how to do that...

argument for generic parameter could not be inferred

swift,nsuserdefaults,loaddata
I'm trying to save an array with NSUserDefaults and then load the array, but I get the error "argument for generic parameter could not be inferred." Is there anything I am doing wrong? No one seems to be having this problem in swift, so I can't find any solutions. IBAction...

Cache results from NSUserDefaults?

ios,objective-c,nsuserdefaults
Trying some iOS programming, and I'm using NSUserDefaults to save a couple NSNumbers my app needs. I am using the typical code to get and set values, e.g. - (NSNumber *)myUserDefaultNumber { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; return [defaults objectForKey:@"XYZ_MyNumber"]; } But what I don't know is runtime cost. Can...

Object cannot be nil for Un used NSUserDefaults key in project

ios,facebook,swift,nsuserdefaults,nsexception
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: client_id) In my current project (Swift) I am getting the above error, even when I haven't used that key anywhere in the project. I got the error after Facebook integration. But the same key...

NSUserDefaultsDidChangeNotification and Today Extensions

ios,swift,nsuserdefaults,ios8-today-widget,today-extension
I am developing an iPhone app with a Today Extension. The app has a Model module that loads from/saves to NSUserDefaults. Since I want this information to be available to both the main app and the extension, I use an app group: let storage = NSUserDefaults(suiteName: "group.etc.etc.etc...") Both the app...

change object get from NSUserDefaults

ios,objective-c,nsmutablearray,nsuserdefaults,nsmutabledictionary
I’d like to change object get from NSUserDefaults. But when executing following code, the app crash with error message: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object’ I have this code. NSUserDefaults* pref = [NSUserDefaults standardUserDefaults]; NSMutableArray* data = [[NSMutableArray alloc]init];...

NSUserDefaults save and reload while using app but reset when app is restarted

ios,objective-c,nsuserdefaults
I have a method to increment a counter if it is the first time a user has been messaged on the particular day. Code below: //here we decide if to increment it or not -(BOOL)canIncrementCountForUser: (NSString *)user { //erase the dictionary if it's a new day [self flushDictionaryIfNeeded]; //load up...

Saving app settings - iOS

ios,cocoa-touch,settings,nsuserdefaults,nsdata
I have an iOS app which loads certain features depending on the settings that the user sets. Currently I am using NSUseDefaults to save and retrieve these settings and it works fine. But from what I understand anyone can view and edit them with a simple XML editor. You don't...

How can I save the state of a button to NSUserDefaults?

ios,objective-c,cocoa,button,nsuserdefaults
I need help trying to do a crude type of confirmation where you need to type: I got it! into a NSTextField then press button1 so that once they do press button1 I make my button2 enabled using -(IBAction)check:(id)sender{ NSString *string = [NSString stringWithValue:@"I Got It!"]; if(field.stringValue isEqualToString:string){ [field setHidden:YES];...

NSUserDefaults not working on Xcode beta with Watch OS2

swift,operating-system,nsuserdefaults,watchkit
I just installed the latest beta of Xcode to try Swift 2 and the improvements made to the Apple Watch development section. I'm actually having an hard time figuring out WHY this basic NSUserDefaults method to share informations between iOS and Watch OS2 isn't working. I followed this step-by-step tutorial...

How to set again user default for dictionary

ios,objective-c,iphone,ios8,nsuserdefaults
HOW To set user default again to dictionary. Create the dictionary object and set value to it. NSMutableDictionary * loginDictionary = [[NSMutableDictionary alloc] init]; [loginDictionary setValue:@"My Address" forKey:@"ADDRESS_KEY"]; [loginDictionary setValue:@"1234567890" forKey:@"PHONE_KEY"]; [[NSUserDefaults standardUserDefaults] setObject:newDictionary forKey:@"INFO_KEY"]; [[NSUserDefaults standardUserDefaults] synchronize]; Now I asses those dictionary value and assign to some other object....

Problems with saving an int in NSUserDefaults iOS

ios,objective-c,nsuserdefaults
I am using the below code to save an int and some other stuff into NSUserDefaults from my AppDelegate. The other array that I'm saving is full of objects that conform to NSCoding, so I don't think that that's an issue. If the current place is not zero, then that...

Crash when I re-enter a TableViewController due to an attempt to write to what I think is a mutable dictionary

ios,objective-c,uitableview,nsuserdefaults,nsmutabledictionary
I have the following nested mutable dictionary which I create and save into NSUSerDefaults self.configDict is { objectsDict = { "40E1507D" = { lastUpdate = "2015-05-30 05:02:40 +0000"; subObjects = { "D84EA15E" = { lastUpdate = "2015-05-30 05:02:40 +0000"; show = 1; title = subObjectOne; }; "F20047D4" = { lastUpdate...

Saving array of strings using NSUserDefaults into another UITableView

ios,uitableview,swift,nsuserdefaults
I've two UITableView with custom cell, the first UITableView has array of string in UILabel and UIButton. This is my FirstViewController(first UITableView) And the secondViewController( second UITableView) has only UILabel. What I'm trying to do is to click for example at the second cell UIButton "add to second table" and...

swift userdefaults settings testing value

swift,nsuserdefaults,empty-string
I need to test if the settings page has been completed when the app starts. What should I test for? This is what I tried but get an error unwrapping. The value is a string. I tried using ObjectForKey and tested for nil but same issue. I am new to...

iOS limit usage of a feature

ios,nsuserdefaults
Problem When A user downloads my application, they'll have the ability to use a certain feature. Say, 5 times. After them times are up, they'll require the iAP to continue using it. However, I have a few problems. I want to make it simple, and just store it in the...

Use data from NSUserDefaults in UIPickerView - pickerView stays empty

ios,xcode,swift,uipickerview,nsuserdefaults
I tried to set up NSUserDefaults last night but an error keeps occurring: ViewController3: save data @IBAction func tappedAddButton(sender: AnyObject) { var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() var exercisesList:NSMutableArray? = userDefaults.objectForKey("exercisesList") as? NSMutableArray var dataSet:NSMutableDictionary = NSMutableDictionary() dataSet.setObject(textField.text, forKey: "exercises") if ((exercisesList) != nil){ var newMutableList:NSMutableArray = NSMutableArray(); for dict:AnyObject in...

[__NSCFNumber length]: unrecognized selector sent to instance with NSUserDefaults

ios,objective-c,ios8,nsuserdefaults,unrecognized-selector
I am creating one app in which I am saving my array of custom object in NSUserDefaults using this below code : [Util setSubProductsArrayPreference:myArray forKey:productId]; //Util.m +(void)setSubProductsArrayPreference:(NSMutableArray *)subProducts forKey:(NSString *)string { for (int i=0; i<subProducts.count; i++) { SubProducts *po=[subProducts objectAtIndex:i]; NSString *st=[NSString stringWithFormat:@"%d",i]; [Util setSubProductsPreference:po forKey:st]; } NSUserDefaults *prefs =...

Open in same view controller as closed on (swift)

swift,view,controller,save,nsuserdefaults
I am making a simple fact app (In swift) and all the facts are in separate view controllers and when the user closes the app, it all goes to the main page and you have to start from fact 1 again. I want to know how to save what view...

NsMutable is not subtype of [anyobject] in swift

ios,swift,nsuserdefaults
I want to get the array from NSUserdefault and store it into NsMutableArray but unfortunately it fails. error NsMutable is not subtype of [anyobject] in swift code arrayImage = NSUserDefaults.standardUserDefaults().arrayForKey("ImageArray") as NSMutableArray I am also trying to do downcast NSArray->NSString like in this post....

How to save fields correctly with NSUserDefaults?

objective-c,nsuserdefaults
I'm creating a program that saves a String from one text field and an integer from a second text field. I am trying to use NSUserDefaults, but I can't seem to get either of them to save correctly when I run the program. It crashes when I press the save...

How to get a variable to wrap NSUserDefaults objects?

ios,swift,nsuserdefaults
I'd like to abstract the underlying storage away, so I'd like to create a variable with getters/setters for NSUserDefaults values. Below I was able to do this with the getter like this and even handle default values: public let userStorage = NSUserDefaults(suiteName: "group.testabcxyz") public var categories: [String] { get {...

NSMutableArrays store only 2 objects

ios,iphone,swift,nsmutablearray,nsuserdefaults
I have a weird problem - my mutable array stores only 2 objects - its count is 1,2,2,2 and doesn't change. My only observation is that it always replaces old values f.x. I have: value1 - 2, value2 - 4 and I add next object f.x. 66 and my array...

Replace elements of an NSMutableArray

ios,arrays,swift,nsuserdefaults
I have 4 variable inputs that I put in my WeatherData Array. My Array seems to add them also in the proper range (i.e. the [0]-[3] but really I want to replace the current info with the new info. What I do initially is: if NSUserDefaults.standardUserDefaults().objectForKey("WeatherData") != nil { WeatherData...

Saving an array of NSURL to NSUserDefaults

swift,nsuserdefaults,nsurl
I have an array of NSURL items like this: var array = [NSURL]() I'm trying to save this to NSUserDefaults: let defaults = NSUserDefaults(suiteName: "group.a.project") defaults?.setObject(array, forKey: "NSURLarray") Will result in it crashing as NSURL can't be stored in NSUserDefaults. How can I save this array of NSURL's to NSUserDefaults,...

Unwrapping NSMutableArray from NSUserDefaults

ios,swift,nsuserdefaults
I am trying to unwrap a NSMutableArray from user defaults, but keep getting the error unexpectedly found nil while unwrapping an Optional value. I tried to check for nil after getting the array, but it is happening on the line that is getting the array from the UserDefaults, so I...

Add path to remote server in iOS app

ios,uiwebview,nsuserdefaults
I try to open a specific path in my app, but nothing is displayed in the UIWebView in my simulator, my orignal code is : - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSString *host = [[NSUserDefaults standardUserDefaults] valueForKey:@"host"]; NSString* complement = @"/manager/"; NSString...

NsuserDefaults key returns (null)

ios,nsuserdefaults
Nsuserdefault key returns "(null)" on initial run after installation. How can i check a key exist or not. I have refferred many links ,it say to check It is nill or not. But it didn't worked. enter code here - (NSString *)getTalkText { NSString *storedUsername = [[NSUserDefaults standardUserDefaults] objectForKey:PERS_STORED_TalkText]; return...

Do NSUserDefaults persist when installing a new build through Testflight?

ios,persistence,nsuserdefaults,testflight
User defaults persist between regular updates, but what about between Testflight builds? I'm guessing they do, but it is a test environment after all. Related to this question, but not the same. I would have tested this myself but my phone is being held for ransom at a repair shop,...

Loading data from nested NSUSERDEFAULTS into UITABLEVIEW

ios,objective-c,uitableview,nsdictionary,nsuserdefaults
I have a DetailViewController which is saving some Data to NSUserDefaults if the user wants. It is like kind of favorite list. Hier is the structure of the saved Defaults: List = { 0002 = ( { Picture = "link to picture.jpg"; Place = "London"; Title = "Flat with Balcony";...

Restore NSUserDefaults data on Apple Watch app

ios,nsuserdefaults,apple-watch
I have an app, it uses NSUserDefaults to store some data from various views and then, later, restore this data in a specific view with all results previously calculated. Well, now I want to make a new Apple Watch compatible version of this app, all I want is to take...

UIPickerView won't display the data loaded from NSUserDefaults - App is crashing while loading data

ios,xcode,swift,uipickerview,nsuserdefaults
I made a first try to use NSUserDefaults in an App with UIPickerViews. But the App is crashing while testing / the data isn't displayed in the PickerView. I still try to fix it myself but some help would be great. ViewController3: Where the user should save data to the...

Save current date via button click into NSUserDefaults

xcode,swift,nsdate,nsuserdefaults
I've been trying to save the current date on the iPhone via Button click to the NSUserDefaults but it won't work. I don't really know how to get the current date, save it as a var and call it in the function. but I've given it a try: @IBAction func...

NSDictionary becomes NSCFString when I save to NSUserDefaults in Swift

swift,nsuserdefaults
NSDictionary becomes NSCFString when I save to NSUserDefaults: class SecondViewController: UIViewController { @IBOutlet var questionforsave: UITextField! @IBOutlet var answerforsave: UITextField! var answersSaved = [String:String]() @IBAction func savePressed(sender: AnyObject) { if questionforsave.text.isEmpty || answerforsave.text.isEmpty{ let alert = UIAlertView() alert.title = "Empty fields" alert.message = "Please Enter Text In Both Text Fields"...

Save custom objects into NSUserDefaults [duplicate]

ios,swift,nsuserdefaults
This question already has an answer here: Saving custom SWIFT class with NSCoding to UserDefaults 2 answers I'm having a news ViewController and a TeamViewController. The TeamViewController contain a tableView of teamObjects which when selected is added into array. I want to add this array into NSUserDefaults so i...

NSUserDefaults key initialization when app starts for the first time

ios,swift,crash,initialization,nsuserdefaults
If I start an app for the first time, the boolean key for a NSUserDefaults is nil and the app crashes when it tries out the state of the setting in an if-statement. I try to initialize the key in viewDidLoad() as follows but the key seems to keep undefined:...

Storing class in NSUserDefaults and accessing in next view

ios,swift,nsuserdefaults
I created a swift class called UserDetails and below is the structure: import Foundation class UserDetailsClass { var fullname: String! var mobile: String! var email: String! var password: String! } In my current View controller , I create an instance and store the values I want to move to next...

cloudkit: how to access main user's attributes?

swift,user,nsuserdefaults,cloudkit
I am fairly new to programing and a total newbie regarding cloudkit. I am trying to make an app in which every user would have a personal avatar, a nickname and so on. The problem is that I don't know how to access the user's account on cloudkit. My solution...

Overwriting NSMutableArray loaded from NSUserDefaults

objective-c,arrays,nsmutablearray,nsarray,nsuserdefaults
So I'm having real problems overwriting an array stored in NSUSerDefaults. Basically I have a checklist of 100 items (defined by bools in an array(which are actually strings at the moment)) and I need to save if each item is checked so when the app loads, the checklist remains as...

Save score in a game with NSUserdefaults

ios,swift,nsuserdefaults
I've made this little app "How many fingers" where the user has to guess how many fingers the computer is holding behind it's back. Now I want it to be able to save the users score with NSUserdefaults, but it's not working. Here is how my code looks right now:...

Saving username and password using UISwitch in Swift

swift,passwords,nsuserdefaults,username,uiswitch
Ive searched a lot of threads and this is my last resort because Ive seen this question asked different ways but not exactly for swift and for Username and password saving. I want my UISwitch when turned on to save my username and password info. I've been trying all day...

Core Data vs NSUserDefaults for logged in user data

ios,core-data,nsuserdefaults
I have an app where I already use Core Data to store a big amount of shops, which a user can view once logged in. I am currently implementing the login part of the app and I looked through many related questions. Most of them suggest using NSUserDefaults for storing...

NSUserDefaults Plist Creation Fails in Swift (but not Objective-C)

objective-c,osx,swift,nsuserdefaults
I'm converting one of my projects from Objective-C to Swift and I've run into an odd snag. Consider the following code (executed in -applicationDidFinishLaunching)... Objective-C Please excuse the messy one-liner [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]]]; In my Objective-C project this works as expected. If I run my...

Why won't app groups work inside my WatchKit extension?

ios,nsuserdefaults,ios-app-extension,watchkit,ios-app-group
I've seen all the other posts of SO about sharing NSUserDefaults data between host apps and app extensions, but mine still doesn't work. Here's everything I've done: Enable App Groups on Xcode's "Capabilities" tab for the extension and host app. Set the group name to "group.com.mycompany.foo" and confirmed the extension...

Swift UnsafePointer(data.bytes).memory crash under some (but not all) circumstances

swift,struct,nsuserdefaults,nsdata
I have the following struct: struct Identity { var id: Int var createdAt: NSDate var string: String var apnsToken: String } Over the course of my application's execution, instances (?) of this struct are turned into NSData (using the following code) and stored in NSUserDefaults: var id = Identity(id: 0,...

iOS app - user defaults using NSUserDefaults, saving on Simulator but not on device

ios,nsuserdefaults
I have an iOS app , that has been saving user defaults using NSUserDefaults, however, all of a sudden , the app is no longer saving defaults on the device , but it works perfectly in the simulator. Here are the methods I am calling to save settings -(void)saveSettings{ defaults...

Convert/Format DateString from NSUserdefaults

ios,string,date,format,nsuserdefaults
I tried to format a String from NSUserDefaults, which holds a Date. The result is (null). My question is: Is there a way to convert this String into a date to format it, or is there a better way? My Code: NSString *c = [prefs objectForKey:@"expiration_date_full"]; NSDateFormatter *dateFormatter = [[NSDateFormatter...

Will app lose the NSUserDefault data on over the air installation? [duplicate]

ios,nsuserdefaults,keychain,over-the-air
This question already has an answer here: Do NSUserDefaults persist through an Update to an app in the Appstore? 5 answers Will app lose the NSUSerDefaults values when I do over the air installation? No app installed in the device Install the app version 1.0 over the air and...

NSTimer and NSUserDefaults

objective-c,nsuserdefaults,nstimer,countdown
the timer will be 23 hours, in format 00:00:00 (hour:min:sec), so when a button is pressed, the timer will start counting down 23 hours, i would like this to be saved by NSUserDefaults, so that whenever i exit the application or switch to another view controller, the remaining time is...

NSUserDefaults setObject:forKey: very time expensive

ios,performance,cocoa-touch,nsuserdefaults
While profiling on the simulator, I noticed that every time I save an NSNumber in in NSUserDefaults it takes a long time, about 600 ms per instance. Is this normal? I have around 5 of these objects I need to save, so that means in total it takes 3000ms which...

Unable to store a NSMutableArray(each instance of array contains a custom object) in NSUserDefaults

ios,objective-c,iphone,nsuserdefaults
It's a custom class: #import <Foundation/Foundation.h> @interface timeTable : NSObject @property (nonatomic) int ID; @property (nonatomic) NSString * type; @property (nonatomic) NSString * time; @property (nonatomic) NSString * busno; @property (nonatomic) NSString * stops; // nothing is done in it's .m file not even synthesise // thats an other class...

Storing Dictionary in NSUserDefaults causing EXC_BAD_ACCESS

xcode,swift,dictionary,nsuserdefaults
//Declarations var scoreIncrement:Int = 0 var team = "" var userScore = Dictionary<String,Int>() //Set Values team = "USA" userScore[team] = 0 //Store in NSUserDefaults NSUserDefaults.standardUserDefaults().setObject(userScore, forKey: "userScore") NSUserDefaults.standardUserDefaults().synchronize() //Increment Score scoreIncrement = 1 userScore[team]! += scoreIncrement Above code gives 'EXC_BAD_ACCESS(code=EXC_I386_GPFLT)' error on last line of the code. However if I...

Expected Declaration Error Xcode 6.2 using Swift

xcode,swift,nsuserdefaults
I'm trying to pass the boolean value of a UISwitch to another class using NSUserDefaults. For some reason, in the class that contains the switches, the if statements that are supposed to set the value to NSUserDefaults cannot read the switch declarations. ViewController.swift @IBOutlet var shrimpSwitch: UISwitch! @IBOutlet var nutSwitch:...

How to implement a URL Scheme for a Browser app in Swift so it opens URLs after the scheme (myapp://example.com)?

ios,swift,nsuserdefaults,url-scheme,openurl
In my Browser app I want to make the URL Scheme of my app (myapp://) to open URLs that come after the myapp:// part. I want to have a user use myapp://http://google.com and it will open Google. I set up the URL scheme itself in the app's Info.plist file, and...

NSUserDefaults properly storing Strings in SpriteKit Swift

ios,string,swift,nsuserdefaults,optional
So I set up a NSUserDefault to store a string in my GameViewController NSUserDefaults.standardUserDefaults().setObject("_1", forKey: "SkinSuffix") The idea is it stores a suffix which I will attach to the end of an image name in order to save what skin of a character the player should use. When I call...

iOS extension adding new NSUserDefaults issue after updating from app store

ios,nsuserdefaults,ios-extensions
My application has authorisation. In return if I logged in I receive a token which I store in NSUserDefaults. How current app works: When I press login button the app sends user name and login to the server, in return app gets a token if success. I have a save...

breaking down use cases of different storage methods in iOS apps

ios,core-data,nsuserdefaults,keychain
I'm learning to build iOS swift apps, and I'd appreciate guidance on what storage options to use for different parts of my app. Perhaps examples of how other professional apps architect their storage would be helpful too. To be specific, I see my options as an independent MySQL DB amazon...

How do I increment and save a int value in Swift?

ios,swift,nsuserdefaults
Im trying to keep track of how many times the user loses in my game. So for every loss it goes up by 1. I also want to save it too so the user could see how many total times they lost. Right now the code I have it works...

OSX NSUserDefaults not Working

objective-c,osx,nsuserdefaults
This code gives me always NO in my application. It does indeed work in any other project I copy it... so something must be messed up with my standardUserDefaults, but I absolutely don't know how this can happen and how to solve it! NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:YES...

How to unarchive custom array with NSUserDefaults?

xcode,swift,nsuserdefaults,nscoder
I'm saving an array of type ClassA to NSUserDefaults. ClassA look like this: class ClassA :NSObject, NSCoding{ init (descriptionParam: String) { self.description = descriptionParam } var description: String? required init(coder aDecoder: NSCoder) { if let description = aDecoder.decodeObjectForKey("description") as? String { self.description = description } } func encodeWithCoder(aCoder: NSCoder) {...

Swift equivalent to category on NSUserDefaults with stored constants

swift,nsuserdefaults
I am accustomed to adding a category to NSUserDefaults to help manage the user settings without exposing the string keys used to store them. The idea was to hide the key names as an internal implementation detail of NSUserDefaults and only expose methods such as setFavoriteColor. @implementation NSUserDefaults (AppDefaults) static...

Array has error after being retrieved from NSUserDefaults

arrays,cocoa-touch,swift,nsuserdefaults,foundation
I have a custom class for which I've implemented the NSCoder protocol. My intended data model is to store an array of these custom classes in NSUserDefaults. I encode it as NSData and store it in an array, which I store in NSUserDefaults. However when I retrieve the stored data...

Loading data back from NSUserDefaults

ios,uitableview,swift,nsuserdefaults
In ViewController3 the user can save some text via button click to the NSUserDefaults (to use it elsewhere). In the same ViewController there is also a tableView (used to delete specific items from NSUserDefaults) So I have to load the data back with: override func viewDidLoad() { super.viewDidLoad() var exercisescopy...

Making an integer not reset after game over

swift,nsuserdefaults
**I feel like this should be really simple but I cant find a tutorial to explain it and unfortunately I'm not experienced enough to solve it myself and basically rely on tutorials to learn. I have a game and if you jump over an object you get a point. Please...

Passing NSMutable array from one view to another

ios,nsmutablearray,nsuserdefaults
I want to add an element to a NSMutableArray in one view and that array should reflect in another view. I am using NSuserDefaults technique for this purpose.. Here's my code: View for adding element - (IBAction)donebutton:(id)sender { NSUserDefaults *defaults = [NSUserDefaults new]; if ([defaults objectForKey:@"arr"]) { self.arrayy = [defaults...

Using NSUserdefaults and creating unique people for gallery

objective-c,xcode,data,nsuserdefaults
Im trying to create gallery of people, to add users to the gallery I would click a "+" a modal pop-over will appear: 2 UITextfield 4 UI Image Views - On press will show Image picker I would like to know how I can get the UITextfield values and the...

Casting struct to NSUserDefaults in Swift?

ios,swift,struct,nsuserdefaults
Is there a way I can cast this Swift data set in someway to a form that is acceptable to NSUserDefauts? i.e. NSObject NSSet? (p.s. I realize NSUserDefaults isn't for this type of data, but I'm just testing) struct Users { var name: String = "" var stores: [Store] }...

“Expected Declaration” Error in Swift in userDefaults

ios,swift,nsuserdefaults
I am trying to save the placeHolderValue in NSUserDefaults, but I am getting an expected declaration error in the third line. let placeHolderValue = 1000 var userDefaults = NSUserDefaults.standardUserDefaults() userDefaults.setValue(placeHolderValue, forKey: "placeholder") userDefaults.synchronize() I've looked everywhere and can't find someone with a similar problem. What am I doing wrong? Thanks!...

NSUserDefaults fail to retrieve image Array

ios,swift,nsuserdefaults
I try to store array of UIImage, it used to work but somehow all of sudden it refused to work. I wrote this test example to check if it's stored properly and I guess the problem is somewhere here let images = NSKeyedArchiver.archivedDataWithRootObject(self.globalImageArray) NSUserDefaults.standardUserDefaults().setObject(images, forKey: "morningImages") NSUserDefaults.standardUserDefaults().synchronize() println("Images saved") let...

How To Make Last Visited Viewcontroller The RootViewController?

objective-c,uiviewcontroller,nsuserdefaults,uistoryboard,appdelegate
I figured it out. Thanks shim for the info!: UIViewController* vc = (UIViewController*)[[UIStoryboard storyboardWithName:@"iPhone4" bundle:nil] instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"]; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"currentViewController"] isEqualToString:@"iPhone4Level1"]) { [self.window setRootViewController: vc]; } ...

how to use updateValue to add an object in Swift

ios,swift,nsuserdefaults
I have a User Struct that I'm casting to Json to be able to get into NSUserDefaults... import Foundation struct User { var name = "" var stores: [Store] = [] init?(json: [String: AnyObject]) { if let name = json["name"] as? String, storesJSON = json["stores"] as? [[String: AnyObject]] { self.name...

Picker saves random data to NSUserDefaults

ios,objective-c,nsuserdefaults,uipickerview
I've been working on a new tips & tricks project for a game called Dofus. In the first view the user is asked to pick their class out of a picker. Then they go to a next view and pick their level and stuff like that. The problem with the...

Where should the sensitive information be stored?

ios,core-data,plist,nsuserdefaults,nsdocumentdirectory
Is it fair to store sensitive data in NSUserDefaults ? I have read that this is a big issue because, NSUserDefaults are stored in plist in binary format, with no encryption, and is stored in your app’s directory. This means that any user, even the “noobiest” one, can tinker with...

Let the tableView delete swipe delete items from NSUserDefaults - How to bring these two functions together?

ios,xcode,uitableview,swift,nsuserdefaults
I want to let the user of my App delete items from the NSUserDefaults out of a tableView by swiping left on the Cell and press "delete". I know both function but I don't know how to bring them together in the right was so that the "remove swipe" affects...

NSUserdefaults not working with NSKeyedArchiver

ios,objective-c,nsuserdefaults,nscoding,nskeyedarchiver
I have a NSMutableArray filled with objects of my Movie class wich i want to save but it doesn't work and i can not figure out why... Movie.h: @interface Movie : NSObject <NSCoding>{ NSString *name; int year; int length; NSString *file_size; int rating; NSArray *genre; NSString *plot; } @property (nonatomic,...

Error while removing items from NSUserDefaults with tableView swipe function

ios,uitableview,swift,nsuserdefaults
I trie to remove items from NSUserDefaults with tableView swipe function. But when I test my App it always crashes after clicking "delete". defining the variable and loading the data back from NSUserDefaults: var exercises:NSMutableArray = NSMutableArray(); ... override func viewDidLoad() { super.viewDidLoad() var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() var exercisesListFromUserDefaults:NSMutableArray? =...

Cannot setBool NSUserDefaults [duplicate]

ios,objective-c,nsuserdefaults
This question already has an answer here: NSUserDefaults. setValue works, Not setBool 4 answers I'm trying to set userDefaults, but it isn't working. Have anyone else experience this problem? Tried both on simulator and device. Xcode 6.3.1 and iOS 8.3 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:YES forKey:@"active"]; BOOL...

Changing from NSUserDefaults to NSCoding

ios,swift,sprite-kit,nsuserdefaults,nscoding
I'm trying to create my first sprite kit swift game, and I have my game data working using nsuserdefaults. I want to make it more safe so I'm attempting to transition to NSCoding, but nothing I've found online has helped me completely and has just confused me (so sorry if...

How to clear out NSUserDefaults on an updated app

ios,objective-c,nsuserdefaults,hockeyapp
I am using HockeyApp and Ship.io to deploy my ios app to multiple testers on every build. In my latest build, I changed the data types of some objects i was saving into NSUserDefaults, and now it crashes because old data stored on everyones local device clashes with this change....

Data to Userdefault encoder class for storing custom object

ios,objective-c,iphone,nsuserdefaults,encode
Can anyone give me any link or file, which could be used globally for a project to Store data to NSUserDefault. Which contains method to save dictionary, array,string,integer all.

Passing Multiple Objects To WatchKit In A NSUserDefaults

swift,nsuserdefaults,watchkit
With the help of some great tutorials and users here, I've had success implementing SwiftyJSON in my app and getting a basic WatchKit app built alongside. My last hurdle to pass is getting my whole set of parsed JSON data to be passed to WatchKit, as to allow me to...