Graphics Programs Reference
In-Depth Information
[self setInfoString:[aDecoder decodeObjectForKey:@"infoString"]];
[self setTitle:[aDecoder decodeObjectForKey:@"title"]];
}
return self;
}
Do the same thing in RSSItem.h .
@interface RSSItem : NSObject
<NSXMLParserDelegate, JSONSerializable , NSCoding >
And in RSSItem.m .
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:title forKey:@"title"];
[aCoder encodeObject:link forKey:@"link"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
[self setTitle:[aDecoder decodeObjectForKey:@"title"]];
[self setLink:[aDecoder decodeObjectForKey:@"link"]];
}
return self;
}
Now that channels and items can be written to the filesystem and loaded back into the ap-
plication, let's figure out when and how this should happen. Typically when you cache
something, you use an all-or-nothing approach: a request either returns all brand-new data
or all cached data. This approach makes sense for Apple's Top Songs RSS feed because
the amount of total data is small. Because the data isn't updated very often, we will return
cached data to the controller unless that data is more than five minutes old.
Caching is another task for the store rather than the controller. The controller doesn't have
to know the details or even whether it is getting cached or new data. ListViewCon-
troller will ask for the RSS feed, and the BNRFeedStore will return the cached data
if it is fresh. Otherwise, it will make the request to Apple's server for fresh data ( Fig-
ure 29.1 ) .
Figure 29.1 Cache flow
 
Search WWH ::




Custom Search