0

I've got an iOS app I am trying to build that presents the user data from a .xlsx (MS Excel file) I have. The file has nearly 11,000 rows, with 20 columns per row. I have built a parser to transform each row into an subclass of NSObject, with each column being an instance variable. I made it NSCoding compliant, added each instance to an NSDictionary, with it's key being the first row of the original file, and archived it. My problem is, I don't want to unarchive such a massive NSDictionary, to access the maximum of 20 or objects with in it, I might need at any given time.

The question is: How do I go about saving this chunk of data in such a way, I don't have 11,000 objects living in the heap, and still be able to load the ones I need into the app while it's running?

keeri
  • 809
  • 2
  • 13
  • 19
Joe Million
  • 147
  • 9

1 Answers1

2

I believe your best option is to export your data to a database.

The simplest solutions are SQLite or CoreData.

I would go with CoreData as it will save you a lot of development time (you will need to spend some time to get acquainted with CoreData though). In addition, it will probably take care of your memory issues regarding holding only the objects you use in memory.

Basically, CoreData is an object graph, which mean that it lets you load portions of the graph only when needed (for SQLite store type).

From what you described, you have a single entity (row with 20 columns) that you would like to access using some kind of query without loading all the entities in the file.

The CoreData equivalent would be:
1)Define the entity in core data (once, in the model designer)
2)Create the CoreData stack (for a simple design this is automatically generated)
3)Create a NSPredicate to select the instances you like
4)Create a NSFetchRequest to define the access to the data
5)Execute the request on the main context using a NSFetchedReaultsController 6)Display your results

You could create a new project that uses core data and see an example of how this works

Dan Shelly
  • 5,991
  • 2
  • 22
  • 26
  • Thanks, I had been working my way through the Big Nerd Ranch Guide to iOS programing, when I had stopped about half way though to piddle around on my own for a bit. I opened up the book to see what page CoreData was on, flipped to it, and found I left my bookmark on the very page they start covering CoreData, I have a bit a reading to do, but I already have a project to learn the concept ready to go. Again, thanks. – Joe Million Apr 27 '13 at 18:44