13

I have a feature on my app that allows users to invite their friends (via facebook, or friends in their address book). Most people will have < 5K friends with some people having more (maybe a max of like 10K friends?).

I want to keep track of the friends they have invited so they do not re-invite them. To accomplish this I am saving a dict of friends in NSUserDefaults to store this information. I am wondering if NSUserDefaults will suffice for this, or if I need to use Core Data.

Also, I am planning on adding a feature to allow them to invite friends to a particular event. (there are many events on our app.) If I want to keep track of which friends have been invited to which event, should I be using Core Data then? Will NSUserDefaults suffice for that? (I am assuming it won't). And lastly, should Core Data be used for that or should that be saved server side?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Atul Bhatia
  • 1,633
  • 5
  • 25
  • 50
  • archive a dictionary to the docs folder. Core Data takes care if you update it (migration). Also there was a bug, every time I added a field, I had to regenerate the header via the tool, I couldn't just update the header without it failing – Stephen J Jun 04 '14 at 09:13

3 Answers3

16

NSUserDefaults is really meant for storing small pieces of data such as settings, preferences, and individual values.

You should use Core Data to store a large list of elements. As far your last question, there is nothing preventing you from using both Core Data and a backend to store your data. In fact, there are frameworks out there to facilitate exactly this. Take a look at RestKit.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Dima
  • 23,484
  • 6
  • 56
  • 83
  • what about for the first part of my question. can I use NSUserDefaults for that? – Atul Bhatia Jun 04 '14 at 09:56
  • You can but depending on how big that structure might get, you may want to just stick with Core Data for that too. – Dima Jun 04 '14 at 10:51
  • Why is it not recommended though? Are there performance consequences when storing lots of data in NSUserDefaults? – mark Oct 01 '17 at 18:29
  • 1
    @mark That's right. UserDefaults are stored in a plist which is saved and loaded in its entirety when you want to write to it or access it. It just becomes inefficient if you put a lot of data in there, such as a huge list. I'm not sure how much data you'd actually need to start experiencing performance issues, though. – Dima Oct 01 '17 at 22:39
1

Your assumption is correct! NSUserDefaults is not sufficient and reliable to store and query the huge amount of data. It's suggestable if you'll have a backend (database on the server) to store events and their invitees to persist consistency of user's information (if user logged in back to your app from other app supportive device then he'll get all information he stored). Also create the tables in database in a way that you can query for your required information easily. Something like, for each of the events, there's some field which stores/update its invites information. When you want to know your single query should come with all your need result. That'll put really good effect of your app on the user that your app is running quite fast.

Hemang
  • 26,840
  • 19
  • 119
  • 186
0

What do you plan to save in your dictionary? If it's only s string then it's ok, but if you plan to store images, I would recommend Core Data.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
tcacciatore
  • 483
  • 6
  • 21