1

I'm storing just one NSArray to NSUserDefaults, but this array may eventually have many objects inside.

Could it be a problem using NSUserDefaults?

Marcos Reboucas
  • 3,409
  • 1
  • 29
  • 35

3 Answers3

2

I would say use Core Data just because you want to simplify your life when dealing with anything more than a hundred data objects within two or more categories or "entities".

Using Core Data means that you're not dumping the entire data set into memory when you load it. Instead, you're using what are called faults which fire when necessary to load additional relationships and associated data.

Migrating the data is also another big benefit of Core Data. When you need to change the data structure, you just create a simple migration and it's done automatically for you. If instead you had an NSArray or NSDictionary in the user defaults, you'd have to iterate over the entire thing and try to change the data structure or migrate an old key name to a new key name. Not an easy task.

Another benefit of Core Data is that it works seamlessly with UITableView and UICollectionView to intelligently search and load only relevant items within your data set which helps improve overall app performance. This is all done via NSFetchedResultsController.

Working with one type of NSArray such as People that only has a hundred people in it shouldn't be a big deal and you can use NSUserDefaults for that as long as the People array doesn't have a lot of associated data stored within it.

Honestly, every app I create that needs any kind of data storage other than basic user preferences uses Core Data now. I don't waste my time on Property Lists or user defaults anymore and I would recommend you not to either.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
  • @MarcosReboucas Glad to help! If this answered your question, please press the checkmark next to my answer to close the question. – iwasrobbed May 13 '13 at 21:31
1

NSUserDefaults is named as it is for a reason. It's designed to store a handful of user preferences and settings for your app, not the bulk of its data. If you're storing anything that resembles a database, NSUserDefaults is not the way to implement it -- use Core Data, as per @iWasRobbed's answer.

davidf2281
  • 1,319
  • 12
  • 20
1

NSUserDefaults only use to store limited amount of data.if you have large amount of data you should go with coreData.

Suraj Gupta
  • 200
  • 9