Reputation: 61
I'm in the process of making an app that will use a lot of data, e.g ~100 entries, each containing several images, >250 words of text and numerous 1 word/ character values.
Im just wondering about the best practise to do this in objective c?
For example, would I have a plain text file that contains all the values and then read it in at run time?
Or would I need to create an object which holds all these values?
I would prefer this to not use a web source as I want the app to be able to run offline.
Upvotes: 1
Views: 2404
Reputation: 124997
A hundred records with perhaps a few dozen fields each is not a lot of data. I'd suggest storing the data as a property list, probably an array of dictionaries. This is about the simplest solution, and probably more than adequate for your needs. Loading your data could be as simple as:
NSArray *records = [[NSArray alloc] initWithContentsOfFile:pathToFile];
Each entry in the array could be a dictionary with a key for each field in the record. This gives you a lot of flexibility. You can of course access each record individually, but you can also use NSPredicate to pick out subsets of the records that match criteria you specify. You can also use key-value coding with the array to get an array of all the values for a particular key. For example, if you want an array of the "name" field for each record, you could say:
NSArray *names = [records valueForKey:@"name"];
There's a place for solutions like SQLite and Core Data, but you probably won't need them for such a small data set.
Upvotes: 2
Reputation: 80603
You have lots of options. You can store the data in plists, create objects for them and serialize out to a file, or use a database. For your particular scenario I would recommend storing in a database like sqlite.
Upvotes: 2