nsuserdefaults

Storing a variable when the app is first installed

我怕爱的太早我们不能终老 提交于 2019-12-01 14:13:18
Attempting to store the variable DateInstalled when the app is first installed, but each time the app loads this variable is overridden by the new date. I am new to Xcode so the answer is probably obvious. I found this code below to store the variable in the user defaults but every time it seems to skip to the else statement. var DateInstalled: NSDate { get { if let returnValue = NSUserDefaults.standardUserDefaults().objectForKey("DateInstalled") as? NSDate { return returnValue } else { NSLog("Saving new Date") return NSDate() // Default value } } set { NSUserDefaults.standardUserDefaults()

Saving UIPrinter to NSUserDefaults

空扰寡人 提交于 2019-12-01 14:06:13
I am trying to save a UIPrinter object like this. -(IBAction)setPrinterInSettings:(id)sender{ UIPrinterPickerController *picker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:self.SavedPrinter]; [picker presentFromRect:self.settingsButton.frame inView:self.view animated:YES completionHandler:^(UIPrinterPickerController *controller, BOOL userDidSelect, NSError *err) { if (userDidSelect) { self.SavedPrinter = controller.selectedPrinter; NSLog(@"self.SavedPrinter == %@",self.SavedPrinter); [self saveCustomObject:self.SavedPrinter key:@"SavedPrinter"]; [

what is the best way for saving username and High Score

为君一笑 提交于 2019-12-01 13:38:34
In my app I need to save a double value (high score) and String (player name) what should i use to get this. any idea will be great. Thank you As deanWombourne said, you can use NSUserDefaults to store these data but it isn't very secure. If you don't want to store this data "in the air", you can take a look to SFHFKeychainUtils by Buzz Andersen to store them in the iPhone Keychain. First of all, copy SFHFKeychainUtils files to your project. Click on the SFHFKeychainUtils.m and click on Get Info. Go to Target tab and check if the box near your target is checked. If not, check it. Control-click

Saving UIPrinter to NSUserDefaults

核能气质少年 提交于 2019-12-01 13:37:35
问题 I am trying to save a UIPrinter object like this. -(IBAction)setPrinterInSettings:(id)sender{ UIPrinterPickerController *picker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:self.SavedPrinter]; [picker presentFromRect:self.settingsButton.frame inView:self.view animated:YES completionHandler:^(UIPrinterPickerController *controller, BOOL userDidSelect, NSError *err) { if (userDidSelect) { self.SavedPrinter = controller.selectedPrinter; NSLog(@"self

How to Store User Entered Details and Get It Back in ios?

偶尔善良 提交于 2019-12-01 13:32:37
问题 How to Store user entered details and Get it Back in ios? I had Following TextFields : UserName , Email , Re-enter Email id , Phone , State , Address , Locality and Pincode . I want to store this Details in Current viewController locally and display this details in Next ViewController .... How many Ways I can Store and Fetch the Details, Does anyone know where I can find more information about this? 回答1: Do you want to keep user Info persistent(1) or you need this data just to represent it

How to save data , in an iOS application?

☆樱花仙子☆ 提交于 2019-12-01 12:53:29
问题 I am developing an application where the user creates an event which has 3 fields: Category , name , event. After the user gives his entry , i have a save button that will save his data for future reference. Then when he opens the app again the data will be shown in a table View. How exactly do i "save" data on iOS ? I know about the NSUserDefaults , but i am pretty sure this is not the way for this example. What i ve done so far : I created a "Note" class with Category , name , event. The

Storing a variable when the app is first installed

梦想与她 提交于 2019-12-01 12:27:47
问题 Attempting to store the variable DateInstalled when the app is first installed, but each time the app loads this variable is overridden by the new date. I am new to Xcode so the answer is probably obvious. I found this code below to store the variable in the user defaults but every time it seems to skip to the else statement. var DateInstalled: NSDate { get { if let returnValue = NSUserDefaults.standardUserDefaults().objectForKey("DateInstalled") as? NSDate { return returnValue } else { NSLog

NSUserDefaults problem

≯℡__Kan透↙ 提交于 2019-12-01 12:14:50
问题 I have this in my app delegate applicationDidFinishLaunching method: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if([defaults objectForKey:@"AcceptTC"] == nil){ NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AcceptTC"]; [defaults registerDefaults:appDefaults]; } and I have this in my RootViewController viewDidLoad method: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if(![defaults boolForKey:@"AcceptTC"]){ UIAlertView

storing [Int:String] dictionaries to user.defaults crashes with SIGABRT error

不羁的心 提交于 2019-12-01 12:02:06
问题 saving a bunch of data using user.default. everything saves fine except one dictionary [Int:String]. The funny part is this, I can save a dictionary [String:Int] fine, but as soon as its [Int:String], it crashes when I run my save function that has my code in it. the console shows the follow: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object { 99 = Jennifer; } for key playernames' thank you 回答1: The Object that you

WatchKit NSUserDefaults and NSKeyedUnarchiver issue

孤街浪徒 提交于 2019-12-01 11:21:50
问题 In my project I have a custom object called Country, which implements NSCoding The code is shared across iphone and watch app by reference. Both app are in the same app group. In my iPhone app I'm using NSUserDefaults to story a Country object, from watch app I'm reading the same object with following code: var defaults = NSUserDefaults(suiteName: "group.my.group") if let data = defaults?.objectForKey("country") as? NSData { if let country = NSKeyedUnarchiver.unarchiveObjectWithData(data) as?