0

I am creating a dictionary in my iOS app that will hold thousands of Strings. The app writes and reads from it very often (100 times whenever the user refreshes the feed), so speed is important. Also, it needs to be saved beyond sessions.

I have tried NSUserDefaults, but it seems that is supposed to be used for immutable dictionaries. Keychain doesn't seem like the right thing to use either.

What should I use to store the dictionary?

stevenA
  • 103
  • 9
  • I think keeping it in NSUserDefaults is ok, you load it when launching and create a mutable copy of it. The frequency you fetch and add on it has nothing to do with storing. – KudoCC Mar 11 '15 at 05:31
  • 100 reads of a dictionary isn't a lot. Just build an nsmutabledictionary and stick it somewhere you can reference it. – Millie Smith Mar 11 '15 at 05:32
  • Or you could try [save nsdictionary to .plist file](http://stackoverflow.com/questions/6311037/save-nsdictionary-to-plist) – Huy Nghia Mar 11 '15 at 05:38

1 Answers1

0

Create a mutable dictionary and keep it as a instance variable in the controller class, that refreshes/adds/edits the information. Speed isn't a factor when u are refreshing as the dictionary doesn't travels like a array, you can directly access the value by its key, you dont have to traverse through the values coming before it. Choose your data structure properly, as if you want to store your strings in such a way that after refreshing the keys will be same but you will edit the values, the NSMutableDictionary is your pal, or else you can use NSSet if you dont want order but don't want any identical records, or an NSMutableArray.

[EDIT] If you want to store your data beyond the app's session then i would say using Core Data, Its lightweight, highly fast it is NOT a Database but rather a type of Persistent storage data. (non volatile). You can also use SQLite but Core data is much faster and light weighted.

Saheb Roy
  • 5,899
  • 3
  • 23
  • 35
  • If it was an instance variable it would be deleted when the app quits, right? Apologies if I wasn't clear, I need it to be stored beyond each session. – stevenA Mar 11 '15 at 05:35
  • I haven't used Core Data before, but I will check it out. Thanks! – stevenA Mar 11 '15 at 05:42
  • I am posting a link for a tutorial, might help you out. http://code.tutsplus.com/tutorials/ios-8-core-data-and-batch-updates--cms-22164 – Saheb Roy Mar 11 '15 at 05:48