Graphics Programs Reference
In-Depth Information
ler that the new items have been fetched so that the interface can be updated. This interac-
tion is shown in Figure 29.2 .
To pull this off, we need to do three things:
• An RSSChannel needs to be able to append new RSSItem s to its items array
and, in doing so, make sure that there are no duplicates and that the items are
ordered by date.
• The method fetchRSSFeedWithCompletion: needs to return the cached
channel immediately and an updated channel when the request completes.
• The ListViewController needs to appropriately handle updating its views
when it receives the cached channel immediately and the updated channel later.
Each of these steps requires a few small steps to achieve. We will start by teaching the
RSSChannel to filter new items into its existing items array. First, declare a new
method in RSSChannel.h .
- (void)addItemsFromChannel:(RSSChannel *)otherChannel;
When the store is asked to fetch the RSS feed, we want it to unarchive the cached channel
from disk, return it, and ask the server for another RSSChannel instance that has the
new items in it. When the request completes, the cached channel should be sent ad-
dItemsFromChannel: with the new channel as an argument. So we want this method
to add items from the new channel to the existing channel. One little problem: because the
RSS feed returns all items from the last 24 hours, if you refresh the feed more than once a
day, you will get duplicates.
The channel, then, has to determine whether it already has an item before adding it to its
list. To do this, instances of RSSItem have to be checked for equality. Every NSObject
subclass implements a method named isEqual: for this purpose. In RSSItem.m ,
override this method to make two RSSItem s equivalent if they have the same link .
- (BOOL)isEqual:(id)object
{
// Make sure we are comparing an RSSItem!
if (![object isKindOfClass:[RSSItem class]])
return NO;
Search WWH ::




Custom Search