1

I am new to iOS programming and I am trying to find the best way to save persistant data. When I developed the android application I used preferences and passed the data around that way. I have a map and a settings button. I would like people to be able to click the settings button and open a new viewcontroller, select some preferences, and then go back to the map and see the generated information. I have the map working and I can generate the information manually, I just am not sure the best way to setup the preferences from the user.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
shinjuo
  • 20,498
  • 23
  • 73
  • 104

4 Answers4

2

Use NSUserDefaults:

You can do something like this:

NSString *data = @"Hello World";

[NSUserDefaults standardUserDefaults] setObject: data forKey:CUSTOM_KEY]];
[[NSUserDefaults standardUserDefaults] synchronize];
Wyetro
  • 8,439
  • 9
  • 46
  • 64
  • 1
    Don't forget that it may not be written out when you think it is; adding a `[[NSUserDefaults standardUserDefaults] synchronize]` is good practice. – Thompson Aug 08 '14 at 17:16
  • I looked into NSUserDefaults and this seems like the best way for such a small amount of data. I really only need to keep track of a date and 3 check boxes. – shinjuo Aug 08 '14 at 17:33
2

Maybe use core data? that is what i use in my projects.

Chris1994
  • 93
  • 6
  • Core data for a few preferences? I don't think that's a good idea. – rmaddy Aug 08 '14 at 16:56
  • @rmaddy good point, For something like this then NSUserDefaults will be the best idea, but if the app gets bigger then i would go for core data. – Chris1994 Aug 08 '14 at 17:05
2

So for something this small, definitely use NSUserDefaults. For when your app starts scaling bigger, you'll need to start looking towards an actual database. Your two main options are sqlite3 or core data. They both provide different strengths, but both can do the job. It just depends if you're more familiar and comfortable working with SQL or not.

LyricalPanda
  • 1,424
  • 14
  • 25
  • I looked into NSUserDefaults and this seems like the best way for such a small amount of data. I really only need to keep track of a date and 3 check boxes. – shinjuo Aug 08 '14 at 17:33
2

There are a lot of ways to store user persistent or temporary datas. Some of them I count below:

  • SQLite DataBase
  • Core Data
  • User defaults
  • File managers
  • Keychain

Despite the problem, you can use either of them.

Shamsiddin Saidov
  • 2,281
  • 4
  • 23
  • 35