Question

This is a pretty basic question, but I have searched all over for an answer that caters to my situation and found little.

I'm using ECSlidingviewController to make a left drawer/menu control like Facebook, Pulse, and many others. (Actually quite surprised this isn't part of the Apple SDK)

When I select an option from my menu controller, it pops the current top controller off, and pushes the view controller selected by menu. My main view is a tableview of local places, and its quite expensive/time consuming to retrieve local spots from a server every time the view is loaded, so I'd like to save the last loaded collection object (My object that wraps a dictionary with simple accessor methods).

I've explored NSCoding/NSKeyed* and Core Data so far and NSCoding seems like a good plan, but I'm not sure if it would be suited to 30 entries of custom objects (each has 640x320 picture and a few strings). At the same time, using core data for a simple collection object seems like building a mansion for a closet. I've also considered trying to keep the view controller around in memory, but that seems way too wasteful. Also, NSUserDefaults doesn't seem to fit the job either. Would the UIKit state preservation techniques work even when the app is in foreground? And finally- would NSURLCache be a good solution to saving the tableview data?

All I want is a quick and standardized way to reload my tableview's last data source without any network requests, or 100 lines of code.

Was it helpful?

Solution

I'd use Core Data and a fetched results controller. If you start off with a master detail template for this then the code is all generated for you. The main benefit is that the saving is transparent for you and memory management is also transparent (you just set the fetch request page size to a suitable value).

A solution using NSCoding will work, and for 30 results may well be faster. If you know you'll never have more than 30 then it could be attractive. But you need to code (and save) and decode yourself and you still have basically the same table data source code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top