Graphics Programs Reference
In-Depth Information
within that channel. Remembering that a store's job is to unburden the controller, the store
should make it really easy for a controller to fetch the RSSChannel instance.
Think back to another store you wrote - the BNRItemStore from Homepwner . In that
application, the controller simply asked the store for all of the items, and the store loaded
the right file from the filesystem and returned the instances of BNRItem the controller
asked for. It looked like this:
NSArray *items = [[BNRItemStore sharedStore] allItems];
BNRFeedStore should make it just as easy for ListViewController . However,
there is a problem: unlike loading from the filesystem, it takes time to make the request to
a web server. BNRFeedStore can't just return the RSSChannel from a method be-
cause that would block the main thread while the request was being processed. This would
prevent the UI from redrawing or accepting events and generally annoy the user:
// This would take a few seconds and we couldn't execute code in the mean time
RSSChannel *channel = [[BNRFeedStore sharedStore] channel];
Instead, the request needs to be handled asynchronously. The ListViewController
will make the request and supply a callback for when the request finishes. The callback
will have access to the RSSChannel so the ListViewController can grab the
channel and reload its table view.
You have already done something like this. In Whereami , the controller made a request to
an instance of CLLocationManager to find the current location. When the request
completed, the location manager returned an instance of CLLocation to the controller
via delegation. Believe it or not, a CLLocationManager is a store object, and it re-
turned data asynchronously to the requesting controller ( Figure 28.5 ).
Figure 28.5 Flow of Whereami
 
Search WWH ::




Custom Search