Graphics Programs Reference
In-Depth Information
@class RSSItem;
@interface BNRFeedStore : NSObject
{
NSManagedObjectContext *context;
NSManagedObjectModel *model;
}
+ (BNRFeedStore *)sharedStore;
@property (nonatomic, strong) NSDate *topSongsCacheDate;
- (void)fetchTopSongs:(int)count
withCompletion:(void (^)(RSSChannel *obj, NSError *err))block;
- (RSSChannel *)fetchRSSFeedWithCompletion:
(void (^)(RSSChannel *obj, NSError *err))block;
- (void)markItemAsRead:(RSSItem *)item;
- (BOOL)hasItemBeenRead:(RSSItem *)item;
@end
Before moving on with the implementation, let's see how it is going to work. Currently,
when the user taps on a row that corresponds to an RSSItem , the ListViewControl-
ler loads that RSSItem into the WebViewController to display it. Now, the
ListViewController will also send the message markItemAsRead: to the
BNRFeedStore with the selected RSSItem . The store will grab the link from the
RSSItem and insert it into Core Data.
Also, each time the ListViewController reloads its table, it will ask the store, “Has
this item been marked as read?” The store will check with Core Data, and the
ListViewController will place a checkmark in the row if the corresponding item
has been read.
In BNRFeedStore.m , add an init method to create the appropriate objects for Core
Data to work.
- (id)init
{
self = [super init];
if (self) {
model = [NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator *psc =
[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSError *error = nil;
NSString *dbPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES) objectAtIndex:0];
dbPath = [dbPath stringByAppendingPathComponent:@"feed.db"];
NSURL *dbURL = [NSURL fileURLWithPath:dbPath];
if (![psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
Search WWH ::




Custom Search