Graphics Programs Reference
In-Depth Information
} else {
NSString *errorString = [NSString stringWithFormat:@"Fetch failed: %@",
[err localizedDescription]];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error"
message:errorString
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
}
};
if (rssType == ListViewControllerRSSTypeBNR)
[[BNRFeedStore sharedStore] fetchRSSFeedWithCompletion:completionBlock];
else if (rssType == ListViewControllerRSSTypeApple)
[[BNRFeedStore sharedStore] fetchTopSongs:10
withCompletion:completionBlock];
NSLog(@"Executing code at the end of fetchEntries");
}
Build and run the application and tap on the Apple segment. Notice that Completion
block called! shows up in the console before the log statement at the end of
fetchEntries when the data is cached. If the cache is out of date and fetched again,
the order of the statements is reversed. The store should really be consistent about when it
executes the callback for the request. In BNRFeedStore.m , add the following code to
fetchTopSongs:withCompletion: .
- (void)fetchTopSongs:(int)count
withCompletion:(void (^)(RSSChannel *obj, NSError *err))block
{
NSString *cachePath =
[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask,
YES) objectAtIndex:0];
cachePath = [cachePath stringByAppendingPathComponent:@"apple.archive"];
NSDate *tscDate = [self topSongsCacheDate];
if (tscDate) {
NSTimeInterval cacheAge = [tscDate timeIntervalSinceNow];
if (cacheAge > -300.0) {
NSLog(@"Reading cache!");
RSSChannel *cachedChannel = [NSKeyedUnarchiver
unarchiveObjectWithFile:cachePath];
if (cachedChannel) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
block(cachedChannel, nil);
}];
return;
}
}
}
Search WWH ::




Custom Search