Reputation: 1430
What would be the best practise and best for user experience to achieve the following?
1:) Retrieve data from JSON
2:) Store in Core Data
3:) Display in UITableViewController
Do i store the JSON first, then populate the table using the stored data?
OR
Do i store it in the Core Data (background process) and populate the table using the JSON for the first time?
I want the user to be presented with a UITableview with minimum load time. Thanks
Upvotes: 0
Views: 397
Reputation: 12768
The course of action in this matter heavily depends on: A. The amount of JSON data you are downloading B. How effective your backend is at only sending necessary JSON results (rather than sending everything in bulk) C. How you are attaching Core Data to your UITableViewController.
I recently made a pretty big project that does exactly this, which involved fetching a pretty big chunk of JSON, parsing it, and inserting it into Core Data. The only time there is any delay is during the initial load. This is how I accomplished it:
[[String: AnyObject]]
: if let result = rawJSON as? [[String: AnyObject]] {}
NSFetchedResultsController
to manage data from Core Data and populate the UITableView
. I use NSFetchedResultsController
rather than managedObjectContext.executeFetchRequest()
because NSFetchedResultsController
has delegate methods that are called every time the managedObjectContext
is updated.Upvotes: 0
Reputation: 188
This is what I would do:
You can also have a last update date on your data so you are only requesting the new data from the web server that isnt already in your local core data DB. This will reduce the amount of data coming down to your ios device.
Upvotes: 1
Reputation: 7591
If you want minimum load time then I'd serve from JSON and that save to CoreData afterwards. That way the user can see content straight away without first having to wait for all the data to be saved (and parsed).
Upvotes: 0