nsuserdefaults

Does NSUserDefaults save objects if the application becomes inactive?

为君一笑 提交于 2019-12-06 16:42:14
For example: NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; [user setObject:textField1.text forKey:@"receive_text1"]; [user setObject:textField2.text forKey:@"receive_text2"]; [user synchronize]; If I leave this app, just like from background to foreground, or relaunching the app Could objects in NSUserDefaults still get the data that I set before? NSUserDefault is persistent. So the data will be saved until you remove them or delete the app from the device. 来源: https://stackoverflow.com/questions/4592550/does-nsuserdefaults-save-objects-if-the-application-becomes-inactive

How can I save a second row of UIPickerView to NSUserDefaults?

本秂侑毒 提交于 2019-12-06 16:35:17
I have pickerView with two rows and I need to save position of both to NSUserDefaults. I have successful saved first row with this code: - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSInteger selectedRow = [thePickerView selectedRowInComponent:0]; [[NSUserDefaults standardUserDefaults] setInteger:selectedRow forKey:@"picker"]; } And I don't get how to add a second one. With this code I bring back the position: -(void)viewWillAppear: (BOOL) animated { NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults

How to save User Name and Password in NSUserDefault?

為{幸葍}努か 提交于 2019-12-06 16:27:34
问题 I need to save User Name and Password in NSUserDefault. I am planning to place a round rect button in IB. On pressing of which the User name and Password would be saved in NSUserDefault, so that when user kills the application and tries to login again after some time, they do not need to enter their login details again. Any help would be highly appreciated. Thanks and best regards, PC 回答1: For Saving Username and Password I will personally suggest to use Keychain as they are more safer than

iOS: Should I use Core Data or NSUserDefaults?

血红的双手。 提交于 2019-12-06 14:49:24
Background: I have an app that retrieves a list of restaurants from a database, each have an individual array of basic information about them (hours, name, address, etc). I would like to retrieve that information from the server on the apps first load, but then have it stored within the app itself, with either NSUserDefaults or Core Data, since the information is unlikely to change. The max number of restaurants I would be storing is about 25, is that a small enough data collection to use NSUserDefaults? I have looked at similar questions with storing data with over 1,000 records, but I am

How to store Array in NSUserDefault in Swift?

六月ゝ 毕业季﹏ 提交于 2019-12-06 13:28:13
问题 So I've been trying for a few hours for a way to store an array to NSUserDefault and print them to the cells but the data is not saving as an array, it basically only saves one value at a time. var emailData = [String]() var passwordData = [String]() @IBAction func addPressed(sender: AnyObject) { let defaults = NSUserDefaults.standardUserDefaults() emailData.append(addEmail.text!) passwordData.append(addPassword.text!) var storedEmail = defaults.objectForKey("emailData") as? [String] ??

Strange NSUserDefaults behavior

橙三吉。 提交于 2019-12-06 12:18:45
While my iPhone app is running I store some data (NSStrings) in the NSUserDefaults. I'm storing the high score for a game just fyi. When I double-tap the home button and kill the app the values I store in NSUserDefaults are often not there when I restart the app. Why is this happening? The code I'm using was working fine in all the pre-multitasking OSs (3.0 etc). From reading/searching the net it looks like doing [NSUserDefaults standardUserDefaults] synchronize]; could help. Any thoughts? Thanks! Killing an app from the taskbar when it's suspended just sends it the SIGKILL message; no

In Monotouch, is it possible to save a generic list to to NSUserDefaults?

最后都变了- 提交于 2019-12-06 11:31:23
I have a List<Hashtable> in my MonoTouch app, and I need to persist it to my settings. NSUserDefaults , however, only takes in things that inherit from NSObject . Is there a simple way to wrap my List in an NSObject that I can store in my settings, or is a quick generic way to encode and decode a Hashtable to a JSON string (or similar)? Or is there a MonoTouch alternative for persisting a small list of Hashtable s? Like @Maxim said there are several approach available. If you want to use NSUserDefaults to store your data then you can serialize it (a .NET feature available to you using

NSUserDefaults refuse to save

纵然是瞬间 提交于 2019-12-06 09:28:52
问题 Start a new single view project and update the main ViewController's viewDidLoad. The intention is to retrieve and increment a value stored in NSUserDefaults and save it. - (void)viewDidLoad { [super viewDidLoad]; NSString *key = @"kTheKey"; NSNumber *number = [[NSUserDefaults standardUserDefaults] objectForKey:key]; NSLog(@"current value is %@", number); NSNumber *incremented = @(number.integerValue + 1); NSLog(@"new value will be %@", incremented); [[NSUserDefaults standardUserDefaults]

Saving map pins to array, Swift

不问归期 提交于 2019-12-06 08:14:32
I am creating a map type application, once the user presses a button a pin is dropped to the map at their current location. I am trying to save map pins to an array so that they remain once the app is closed. Here is my code so far: func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location = locations.last let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude) let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.004, longitudeDelta: 0.004)) self

How to save My Data Type in NSUserDefault?

无人久伴 提交于 2019-12-06 07:38:02
I want to save My Data Type temporary in NSUserDefault. this data later pull back. I tried to following code. MyObject *myObject = [[MyObject alloc] init]; [[NSUserDefaults standardUserDefaults] setObject:myObject forKey:@"kMyObject"]; but console show to text me following message. -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<MyObject: 0x4aadb0>' of class 'MyObject'. Note that dictionaries and arrays in property lists must also contain only property values. I can ignore these messages and to force pull out from NSUserDefault. MyObject *getObject = [