Reputation: 21019
I am reading a JSON feed with about 300 array records. Each record is an object with about 8 entries. Is that a lot to store locally in a dictionary upon start up?
If so, should I just read data from the feed online each time data is requested?
Upvotes: 0
Views: 107
Reputation: 63667
The approach with the less amount of code is to store the dictionary in a plist and query the data yourself. The iPhone can handle 300 objects in memory without delays so I wouldn't bother with anything else unless I had to. When to refresh the feed depends on your application logic.
NSString *path = [[NSBundle mainBundle] pathForResource:@"feed" ofType:@"plist"];
[dict writeToFile:path atomically:YES]; // write
[dict dictionaryWithContentsOfFile:path]; // read
[dict enumerateKeysAndObjectsUsingBlock:^(id key,id obj,BOOL *stop){ //iterate
NSLog(@"%@",[NSString stringWithFormat:@"%@=%@", key, obj]);
}];
For a little more performance use a binary plist. If you have to make complex queries then use NSPredicate
or Core Data.
Upvotes: 2
Reputation: 96927
If it doesn't change often, you could cache it into a Core Data store, and update individual records that are different, deleted or newly added, instead of recreating the store on start-up.
Even if it does change often, another advantage of using CD is that you can quickly query your Core Data store for specific records, instead of (possibly) iterating through each record.
Upvotes: 3
Reputation: 28720
Yes you should just read data from the feed online each time data is requested. Although 300 array records is not too much large data. But in case of live feeds you should always read the data each time data is requested.
Upvotes: -1