0

I have a bunch of text fields where the user types in their data. There is 6 text fields for each day (excl. Sat, Sun) and I need the data (string text) in the textfields to be saved so that they are their on next launch.

How would I go about doing this, thanks!

Volker
  • 4,640
  • 1
  • 23
  • 31

2 Answers2

0

You can use NSUserDefaults :

[[NSUserDefaults standardUserDefaults] setObject:_sundayTextField.text ForKey:@"Sunday"];
[[NSUserDefaults standardUserDefaults] synchronize]; // Writes modifications to disk thus making your data persistent between launches

And when your text fields are created :

_sundayTextField = (NSString*)[NSUserDefaults standardUserDefaults] objectForKey:@"Sunday"];

Do this for the other days as well and make sure the object stored in the user defaults dictionary is not null (if so just leave the text field empty or use an initial value).

NSUserDefaults is easy to use and is persistent between launches. For more complex data CoreData is preferred.

giorashc
  • 13,691
  • 3
  • 35
  • 71
0

You have a lot of choices

  1. NSUserDefaults - How to save data with NSUserDefaults using data from NSMutableArray
  2. Write the data to a plist and reload it - iPhone read/write .plist file
  3. CoreData - http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started

Really depends what you are hoping to achieve with the data you are storing

Community
  • 1
  • 1
Flexicoder
  • 8,251
  • 4
  • 42
  • 56